zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
use lazy_static::lazy_static;

use uaparser::{Parser, UserAgentParser};

pub trait UserAgentParserExt {
    fn from_yaml_str(yaml: &str) -> Self;
}

lazy_static! {
    pub static ref USER_AGENT_PARSER: UserAgentParser = {
        // 编译时嵌入 YAML 内容
        const UA_YAML: &str = include_str!("regexes.yaml");
        UserAgentParser::from_yaml_str(UA_YAML)
    };
}

// "Mozilla/5.0 (X11; Linux x86_64; rv:2.0b8pre) Gecko/20101031 Firefox-4.0/4.0b8pre"
pub fn parse(user_agent_string: &str) -> uaparser::Client<'_> {
    let _client = USER_AGENT_PARSER.parse(user_agent_string);

    // client.device
    // client.os
    // client.user_agent
    _client
}

impl UserAgentParserExt for UserAgentParser {
    fn from_yaml_str(yaml: &str) -> Self {
        UserAgentParser::from_bytes(yaml.as_bytes()).expect("Invalid YAML in embedded regexes")
    }
}