Crate uaparser

Source
Expand description

This crate is an implementation of a User Agent Parser, similar to those found as part of the UA-Parser Community. It tries to remain as consistent with the other implementations as possible while remaining simple and legible.

let ua_parser = UserAgentParser::from_yaml("./src/core/regexes.yaml").expect("Parser creation failed");
let user_agent_string =
    String::from("Mozilla/5.0 (X11; Linux x86_64; rv:2.0b8pre) Gecko/20101031 Firefox-4.0/4.0b8pre");
let client = ua_parser.parse(&user_agent_string);

let device = ua_parser.parse_device(&user_agent_string);
let os = ua_parser.parse_os(&user_agent_string);
let user_agent = ua_parser.parse_user_agent(&user_agent_string);

assert_eq!(client.device, device);
assert_eq!(client.os, os);
assert_eq!(client.user_agent, user_agent);

Alternatively you can use the UserAgentParserBuilder to create a parser:

let ua_parser = UserAgentParser::builder().build_from_yaml("./src/core/regexes.yaml").expect("Parser creation failed");
let user_agent_string =
    String::from("Mozilla/5.0 (X11; Linux x86_64; rv:2.0b8pre) Gecko/20101031 Firefox-4.0/4.0b8pre");
let client = ua_parser.parse(&user_agent_string);

let device = ua_parser.parse_device(&user_agent_string);
let os = ua_parser.parse_os(&user_agent_string);
let user_agent = ua_parser.parse_user_agent(&user_agent_string);

assert_eq!(client.device, device);
assert_eq!(client.os, os);
assert_eq!(client.user_agent, user_agent);

Structs§

Client
Houses the Device, OS, and UserAgent structs, which each get parsed out from a user agent string by a UserAgentParser.
Device
Describes the Family, Brand and Model of a Device
OS
Describes the Family as well as the Major, Minor, Patch, and PatchMinor versions of an OS
UserAgent
Describes the Family as well as the Major, Minor, and Patch versions of a UserAgent client
UserAgentParser
Handles the actual parsing of a user agent string by delegating to the respective SubParser

Enums§

Error

Traits§

Parser