fast_uaparser

Crates.iofast_uaparser
lib.rsfast_uaparser
version2.0.1
sourcesrc
created_at2019-08-10 16:52:24.852519
updated_at2020-02-16 17:14:25.639803
descriptionRegex-based parser for User-Agent request headers
homepage
repositoryhttps://gitlab.com/philbooth/uaparser-rs
max_upload_size
id155621
size47,757
Phil Booth (philbooth)

documentation

https://philbooth.gitlab.io/uaparser-rs/fast_uaparser/

README

fast_uaparser

Build status Crate status Downloads License

Parse User-Agent request header strings.

How does it work?

Parsers are derived from regular expressions published in the ua-parser/ua-core repository. The regular expressions are fetched in a custom build step, then used to generate static Rust code that is compiled into the lib.

There is a one-off initialisation cost to load the parser objects at runtime, which is paid when you call the init function. If init is not called explicitly, initialisation occurs lazily instead and parsing will block until it finishes.

How do I install it?

Add it to your dependencies in Cargo.toml:

[dependencies]
fast_uaparser = "1"

How do I use it?

For more detailed information see the API docs, but the general gist is as follows:

use fast_uaparser::{Device, OperatingSystem, UserAgent};

// Pay initialisation costs up-front
fast_uaparser::init().unwrap();

// Parse user-agent information
let ua: UserAgent =
    "Mozilla/5.0 (X11; Linux i686; rv:70.0) Gecko/20100101 Firefox/70.0"
        .parse()
        .unwrap();

assert_eq!(ua.family, "Firefox");
assert_eq!(ua.version.major.unwrap(), "70");
assert_eq!(ua.version.minor.unwrap(), "0");
assert!(ua.version.patch.is_none());
assert!(ua.version.patch_minor.is_none());

// Parse OS information
let os: OperatingSystem =
    "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1"
        .parse()
        .unwrap();

assert_eq!(os.family, "iOS");
assert_eq!(os.version.major.unwrap(), "12");
assert_eq!(os.version.minor.unwrap(), "2");
assert!(os.version.patch.is_none());
assert!(os.version.patch_minor.is_none());

// Parse device information
let device: Device =
    "Mozilla/5.0 (Windows Mobile 10; Android 8.0.0; Microsoft; Lumia 950XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.89 Mobile Safari/537.36 Edge/40.15254.369"
        .parse()
        .unwrap();

assert_eq!(device.family, "Lumia 950XL");
assert_eq!(device.brand.unwrap(), "Nokia");
assert_eq!(device.model.unwrap(), "Lumia 950XL");

How do I set up the dev environment?

f you don't already have Rust installed, get that first using rustup:

curl https://sh.rustup.rs -sSf | sh

Then you can build the project:

cargo b

And run the tests:

cargo t

Where are the API docs?

Here.

Where is the change log?

Here

What license is it released under?

Apache-2.0.

Commit count: 31

cargo fmt