expression

Uri: distinguish path and query

A request target can be an origin-form path with a query and no scheme or host. The path accessor does not include the query. A URI object is not a DNS lookup. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): /books page=2 true Common mistake: Routing on the entire raw target when only the path determines the route.

Formal Syntax & Structure

rust syntaxrust
http::Uri::path(); query()

Working Example

Example Snippetrust
fn main() {    let target: http::Uri = "/books?page=2".parse().unwrap();    println!("{} {}", target.path(), target.query().unwrap());    println!("{}", target.host().is_none());}
Rust Reference