expression

Url: parse scheme, host, port and path

The external url crate implements WHATWG-style URL parsing. An absolute URL exposes components for inspection. Parsing may normalize input and never establishes that a destination is safe or reachable. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): https example.com 8443 /books top Common mistake: Using string splitting as a general URL parser.

Formal Syntax & Structure

rust syntaxrust
url::Url::parse(text) -> Result<Url, ParseError>

Working Example

Example Snippetrust
fn main() {    let u = url::Url::parse("https://example.com:8443/books?q=rust#top").unwrap();    println!("{} {} {} {}", u.scheme(), u.host_str().unwrap(), u.port().unwrap(), u.path());    println!("{}", u.fragment().unwrap());}
Rust Reference