1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
use std::ffi::CString; use crate::values::PropertyValue; pub trait DeviceMatch { fn get_property(&self, property_type: PropertyName) -> Option<PropertyValue>; } pub trait DeviceDetector<'detector, M:DeviceMatch + 'detector> { fn match_by_user_agent(&'detector self, user_agent: &String) -> Option<M>; } pub type PropertyIndexes = [i32;10]; pub static PROPERTY_INDEXES_EMPTY:PropertyIndexes = [-1;10]; pub enum PropertyName { DeviceType, IsSmartPhone, IsTablet, HardwareName, HardwareModel, HardwareVendor, PlatformName, PlatformVersion, BrowserName, BrowserVersion } impl PropertyName { pub fn as_str(&self) -> &'static str { match self { PropertyName::DeviceType => "DeviceType", PropertyName::IsSmartPhone => "IsSmartPhone", PropertyName::IsTablet => "IsTablet", PropertyName::HardwareName => "HardwareName", PropertyName::HardwareModel => "HardwareModel", PropertyName::HardwareVendor => "HardwareVendor", PropertyName::PlatformName => "PlatformName", PropertyName::PlatformVersion => "PlatformVersion", PropertyName::BrowserName => "BrowserName", PropertyName::BrowserVersion => "BrowserVersion" } } pub fn as_cstring(&self) -> CString { CString::new(self.as_str()).expect("CString::new failed") } } impl From<&PropertyName> for usize { fn from(property_type: &PropertyName) -> Self { match property_type { PropertyName::DeviceType => 0, PropertyName::IsSmartPhone => 1, PropertyName::IsTablet => 2, PropertyName::HardwareName => 3, PropertyName::HardwareModel => 4, PropertyName::HardwareVendor => 5, PropertyName::PlatformName => 6, PropertyName::PlatformVersion => 7, PropertyName::BrowserName => 8, PropertyName::BrowserVersion => 9 } } }