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 = {
const UA_YAML: &str = include_str!("regexes.yaml");
UserAgentParser::from_yaml_str(UA_YAML)
};
}
pub fn parse(user_agent_string: &str) -> uaparser::Client<'_> {
let _client = USER_AGENT_PARSER.parse(user_agent_string);
_client
}
impl UserAgentParserExt for UserAgentParser {
fn from_yaml_str(yaml: &str) -> Self {
UserAgentParser::from_bytes(yaml.as_bytes()).expect("Invalid YAML in embedded regexes")
}
}