Sign in

    vicoproplus/moon_ua_parser/src/ua_parser does not have a README file

    UaError

    pub suberror UaError {
    RegexpCompileError(String)
    } derive(Eq, Show)

    Errors raised by the ua_parser package.

    Currently only reports failures to compile a uap-core rule; later tasks enrich payloads with rule-location context.

    Browser

    pub(all) struct Browser {
    family : String
    major : String?
    minor : String?
    patch : String?
    patch_minor : String?
    rule_index : Int?
    } derive(Eq, Show)

    The browser component of a parsed user agent.

    family is the browser family name (for example "Chrome"); it is "Other" when no browser rule matched. The version fields carry the dotted version segments extracted from the matched rule; each is None when the rule provides no corresponding capture (an empty capture also counts as unknown).

    Device

    pub(all) struct Device {
    family : String
    brand : String?
    model : String?
    rule_index : Int?
    } derive(Eq, Show)

    The device component of a parsed user agent.

    family is the device family name (for example "SM-G960F"); it is "Other" when no device rule matched. brand and model are None when the matched rule does not supply them.
    pub(all) struct OS {
    family : String
    major : String?
    minor : String?
    patch : String?
    patch_minor : String?
    rule_index : Int?
    } derive(Eq, Show)

    The operating-system component of a parsed user agent.

    family is the OS family name (for example "Android"); it is "Other" when no OS rule matched. The version fields carry the dotted version segments extracted from the matched rule; each is None when the rule provides no corresponding capture (an empty capture also counts as unknown).

    UaInfo

    pub(all) struct UaInfo {
    browser : Browser
    os : OS
    device : Device
    } derive(Eq, Show)

    The full result of parsing a user agent: browser, operating system and device, each described by its own component struct. Produced by parse; the three components always exist (a component whose rules all miss reports "Other" in family and None in every other field).

    parse

    fn parse(ua : String, with_rule_index? : Bool) -> Result[UaInfo, UaError]

    Parse a user-agent string into its browser, OS and device components.

    Semantics follow uap-python: per domain, rules are tried in order and the first match wins; a domain whose rules all miss reports family "Other" with every other field None. Parsing never fails with the precompiled rule set, so the returned Result is always Ok today.

    Example: parse("Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") yields Ok with browser Chrome 120.0.0, OS Windows 10, and device family "Other".

    T-09 — with_rule_index (optional, default false): when true, each component's rule_index is Some(i) where i is the 0-based position of the rule that produced that component within its domain's rule list (@rules.ua_rules / @rules.os_rules / @rules.device_rules, i.e. the uap-core regexes.yaml rule order for user_agent_parsers / os_parsers / device_parsers). A domain whose rules all miss reports rule_index: None — the "Other" fallback is not produced by any rule. The index is diagnostic metadata only: parsing behavior is identical with and without it. With the default with_rule_index=false every rule_index is None, so results are byte-identical to pre-T-09 output (backward-compatible: parse(ua) keeps its meaning).

    parse_browser

    fn parse_browser(ua : String) -> Browser

    Parse only the browser (user-agent) component.

    First matching UA rule wins; family comes from the rule's family template (literal or $1 substitution), and the version segments fall back to capture groups 2/3/4/5 (missing or empty group -> None). When no rule matches, family is "Other" and all versions are None.

    Example: parse_browser("Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") yields family "Chrome", major "120", minor "0", patch "0", patch_minor "0".

    T-09: this entry point never requests rule indices, so the returned rule_index is always None (the diagnostic index is available via parse(ua, with_rule_index=true)).

    parse_device

    fn parse_device(ua : String) -> Device

    Parse only the device component.

    First matching device rule wins; family falls back to capture group 1, brand comes only from a brand template (no group fallback — absent template means None), and model falls back to capture group 1. When no rule matches, family is "Other" and brand/model are None.

    Example: parse_device("Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like MacOS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.3 Mobile/15E148DuckDuckGo/7 Safari/605.1.15") yields family "iPhone", brand "Apple", model "iPhone".

    T-09: this entry point never requests rule indices, so the returned rule_index is always None (the diagnostic index is available via parse(ua, with_rule_index=true)).

    parse_os

    fn parse_os(ua : String) -> OS

    Parse only the operating-system component.

    First matching OS rule wins; each of the four version segments evaluates its template (or falls back to capture groups 2..5) under uap-python replacer semantics: the whole substituted template is stripped once and an empty result becomes None. When no rule matches, family is "Other" and all versions are None.

    Example: parse_os("Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") yields family "Windows", major "10", and None for the rest.

    T-09: this entry point never requests rule indices, so the returned rule_index is always None (the diagnostic index is available via parse(ua, with_rule_index=true)).