Skip to main content

Crate url_static

Crate url_static 

Source
Expand description

url-static provides a simple url! macro for URL validation at compile-time.

§Examples

use url_static::url;

// ✅ These will for sure work:
let api = url!("https://api.example.com");
assert_eq!(api, Url::parse("https://api.example.com").unwrap());

let test = url!("http://localhost/");
assert_eq!(test, Url::parse("http://localhost/").unwrap());

let mailto = url!("mailto:also_works_for_mailto@example.com");
assert_eq!(mailto, Url::parse("mailto:also_works_for_mailto@example.com").unwrap());

// ✅ It even works with other macros:
let repo = url!(env!("CARGO_PKG_REPOSITORY"));
assert_eq!(repo, Url::parse(env!("CARGO_PKG_REPOSITORY")).unwrap());
// ❌ This won't compile, because it'll never parse:
let woops = url!("https:// api.example.com");

§Feature flags

  • unstable — Enables behavior that relies on Rust’s nightly toolchain. All macros are expanded more reliably, and aren’t limited to basic env! and concat! cases.

    See https://github.com/rust-lang/rust/issues/90765 for the status of the relevant feature.

Macros§

url
Ensures that the given expression is a valid URL string.