uaparser
Pure-Rust user-agent parser built on the shared uap-core regex definitions.
Repository Health
Technical Analysis
uaparser is a Rust implementation of the User Agent Parser, part of the wider UA-Parser community that spans many languages. It reads the standard regexes.yaml file from uap-core and turns raw User-Agent strings into structured client (browser), operating system, and device information. The crate aims to stay consistent with the other implementations while keeping the API small and the code legible.
What You Get
- A Parser type built directly from the standard uap-core
regexes.yamldefinitions - Structured Client, OS, and Device results extracted from any User-Agent string
- Consistency with the broader UA-Parser ecosystem across languages
- Serde-based loading of the regex file with lazy, one-time compilation for reuse
Common Use Cases
- Enriching web analytics with browser, OS, and device breakdowns
- Tailoring responses or served content based on the requesting client
- Detecting bots and crawlers from their User-Agent signatures
Under The Hood
Architecture — The crate is organised around a UserAgentParser built from the uap-core regexes.yaml. src/file.rs and the parser module deserialize the YAML into regex definition tables via serde, and client.rs, os.rs, and device.rs each hold the matching logic for their slice of the result. A parsed Client aggregates the user-agent, OS, and device sub-results, so one pass over the compiled regex list yields all three facets.
Tech Stack — Rust 2018 edition. Core dependencies are regex for matching, serde/serde_derive/serde_yaml for loading the definitions, lazy_static for one-time initialization, and derive_more for boilerplate reduction. criterion powers the benchmark suite under benches/.
Code Quality — The source is split into small, single-responsibility modules and mirrors the shared UA-Parser conformance model, which keeps behavior predictable across languages. Tests rely on the uap-core submodule for canonical fixtures, and a criterion benchmark tracks parsing throughput.
API Design — The surface is intentionally minimal: construct a parser from the YAML, then call parse (or the client/os/device helpers) on any string. Because the compiled parser is reused, the ergonomics favor build-once, parse-many, which is the common real-world pattern.