Skip to content

ttsugriy/rust-1

 
 

Repository files navigation

Rust bindings for Ada

Fast WHATWG specification compliant URL parser for Rust.

Usage

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

[dependencies]
ada-url = { version = "1", features = ["derive"] }

Here is an example illustrating a common usage:

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 3.34 times faster URL parsing compared to url

parse/ada_url           time:   [2.0790 µs 2.0812 µs 2.0835 µs]
                        thrpt:  [369.84 MiB/s 370.25 MiB/s 370.65 MiB/s]
                        
parse/url               time:   [6.9266 µs 6.9677 µs 7.0199 µs]
                        thrpt:  [109.77 MiB/s 110.59 MiB/s 111.25 MiB/s]

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.
Send Used to declare that the type can be transferred across thread boundaries.

About

Rust bindings for Ada URL parser

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%