Skip to main content

url

Macro url 

Source
url!() { /* proc-macro */ }
Expand description

Ensures that the given expression is a valid URL string.

§Proc-macro

Expands to url::Url::parse with the given value if successful. The value must be or resolve to a string literal that is valid according to the url crate’s parser.

§Errors

Causes a compiler error if the given value is not a string literal or a macro that we can resolve to a string literal, or if the value is not a well-formed URL.

§Examples

let api = url!("https://api.example.com/v0/sample");
assert_eq!(api, Url::parse("https://api.example.com/v0/sample").unwrap());

let repo = url!(env!("CARGO_PKG_REPOSITORY"));
assert_eq!(repo, Url::parse(env!("CARGO_PKG_REPOSITORY")).unwrap());