expression

Url::join: relative resolution

Resolve a reference against a base URL. A relative path can replace the last segment, and an absolute reference can replace the entire destination. Do not treat joining untrusted text as a same-origin guarantee. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): https://example.com/docs/intro.html https://example.com/help example.org Common mistake: Assuming a resolved reference always stays under the base path or host.

Formal Syntax & Structure

rust syntaxrust
base.join(reference) -> Result<Url, ParseError>

Working Example

Example Snippetrust
fn main() {    let base = url::Url::parse("https://example.com/docs/index.html").unwrap();    println!("{}", base.join("intro.html").unwrap());    println!("{}", base.join("/help").unwrap());    println!("{}", base.join("https://example.org/").unwrap().host_str().unwrap());}
Rust Reference