Rust bindings for Ada

Fast WHATWG specification compliant URL parser for Rust.

Usage

Add the following as a dependency to your project (Cargo.toml):

toml [dependencies] ada-url = "1"

Here is an example illustrating a common usage:

Rust use ada_url::Url; fn main() { let mut u = Url::parse("http://www.google:8080/love#drug", None).expect("bad url"); println!("port: {:?}", u.port()); println!("hash: {:?}", u.hash()); println!("pathname: {:?}", u.pathname()); println!("href: {:?}", u.href()); u.set_port("9999"); println!("href: {:?}", u.href()); }

Performance

Ada is fast. The benchmark below shows 2 times faster URL parsing compared to url

Running bench/parse.rs (target/release/deps/parse-dff65469468a2cec) url_parse/ada_parse time: [2.5853 µs 2.5982 µs 2.6115 µs] change: [-3.8745% -2.9874% -2.0620%] (p = 0.00 < 0.05) Performance has improved. Found 2 outliers among 100 measurements (2.00%) 1 (1.00%) low mild 1 (1.00%) high severe url_parse/servo_parse time: [5.5127 µs 5.6287 µs 5.8046 µs] change: [+0.7618% +3.0977% +6.5694%] (p = 0.01 < 0.05) Change within noise threshold. Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high severe

Implemented traits

Url implements the following traits. | Trait(s) | Description | | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Display | Provides to_string and allows for the value to be used in format! macros (e.g. println!). | | Debug | Allows debugger output in format macros, ({:?} syntax) | | PartialEq, Eq | Allows for comparison, url1 == url2, url1.eq(url2) | | PartialOrd, Ord | Allows for ordering url1 < url2, done so alphabetically. This is also allows Url to be used as a key in a BTreeMap | | Hash | Makes it so that Url can be hashed based on the string representation. This is important so that Url can be used as a key in a HashMap | | FromStr | Allows for use with str's parse method | | TryFrom<String>, TryFrom<&str> | Provides try_into methods for String and &str | | Borrow<str>, Borrow<[u8]> | Used in some crates so that the Url can be used as a key. | | Deref<Target=str> | Allows for &Url to dereference as a &str. Also provides a number of string methods | | AsRef<[u8]>, AsRef<str> | Used to do a cheap reference-to-reference conversion. |