From 83e1979e71439f6f0cc9d884c5523a4fb8db8e9d Mon Sep 17 00:00:00 2001 From: Hideo Hattori <hattori-h@klab.com> Date: Fri, 2 Feb 2018 12:55:14 +0900 Subject: [PATCH 1/3] use cargo +nightly --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be54948..2271278 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Some(WootheeResult { name: "Internet Explorer", category: "pc", os: "Windows 7", ## Benchmark ``` -$ rustup run nightly cargo bench +$ cargo +nightly bench running 3 tests test bench_stabilizer ... bench: 14 ns/iter (+/- 1) test bench_uap ... bench: 210,071,986 ns/iter (+/- 27,302,537) From 3a08b8cd561e3a12777bee28b048dfe7f96c02d0 Mon Sep 17 00:00:00 2001 From: Hideo Hattori <hattori-h@klab.com> Date: Fri, 2 Feb 2018 14:33:44 +0900 Subject: [PATCH 2/3] separate lifetime of the Parser and WootheeResult (for #5) --- src/dataset.rs | 902 ++++++++++++++++++++--------------------- src/parser.rs | 168 ++++---- templates/dataset.tmpl | 12 +- 3 files changed, 541 insertions(+), 541 deletions(-) diff --git a/src/dataset.rs b/src/dataset.rs index 4de112c..bf9412a 100644 --- a/src/dataset.rs +++ b/src/dataset.rs @@ -3,907 +3,907 @@ use std::collections::HashMap; use parser::WootheeResult; lazy_static! { - pub static ref DATASET: HashMap<&'static str, WootheeResult<'static>> = { + pub static ref DATASET: HashMap<&'static str, WootheeResult> = { let mut dataset = HashMap::new(); dataset.insert("MSIE", WootheeResult { - name: "Internet Explorer", - browser_type: "browser", - category: "", - os: "", + name: "Internet Explorer".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Microsoft", + vendor: "Microsoft".to_string(), version: "".to_string(), }); dataset.insert("Edge", WootheeResult { - name: "Edge", - browser_type: "browser", - category: "", - os: "", + name: "Edge".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Microsoft", + vendor: "Microsoft".to_string(), version: "".to_string(), }); dataset.insert("Chrome", WootheeResult { - name: "Chrome", - browser_type: "browser", - category: "", - os: "", + name: "Chrome".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Google", + vendor: "Google".to_string(), version: "".to_string(), }); dataset.insert("Safari", WootheeResult { - name: "Safari", - browser_type: "browser", - category: "", - os: "", + name: "Safari".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Apple", + vendor: "Apple".to_string(), version: "".to_string(), }); dataset.insert("Firefox", WootheeResult { - name: "Firefox", - browser_type: "browser", - category: "", - os: "", + name: "Firefox".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Mozilla", + vendor: "Mozilla".to_string(), version: "".to_string(), }); dataset.insert("Opera", WootheeResult { - name: "Opera", - browser_type: "browser", - category: "", - os: "", + name: "Opera".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Opera", + vendor: "Opera".to_string(), version: "".to_string(), }); dataset.insert("Vivaldi", WootheeResult { - name: "Vivaldi", - browser_type: "browser", - category: "", - os: "", + name: "Vivaldi".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Vivaldi Technologies", + vendor: "Vivaldi Technologies".to_string(), version: "".to_string(), }); dataset.insert("Sleipnir", WootheeResult { - name: "Sleipnir", - browser_type: "browser", - category: "", - os: "", + name: "Sleipnir".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Fenrir Inc.", + vendor: "Fenrir Inc.".to_string(), version: "".to_string(), }); dataset.insert("Webview", WootheeResult { - name: "Webview", - browser_type: "browser", - category: "", - os: "", + name: "Webview".to_string(), + browser_type: "browser".to_string(), + category: "".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "OS vendor", + vendor: "OS vendor".to_string(), version: "".to_string(), }); dataset.insert("Win", WootheeResult { - name: "Windows UNKNOWN Ver", - browser_type: "os", - category: "pc", - os: "", + name: "Windows UNKNOWN Ver".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Win10", WootheeResult { - name: "Windows 10", - browser_type: "os", - category: "pc", - os: "", + name: "Windows 10".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Win8.1", WootheeResult { - name: "Windows 8.1", - browser_type: "os", - category: "pc", - os: "", + name: "Windows 8.1".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Win8", WootheeResult { - name: "Windows 8", - browser_type: "os", - category: "pc", - os: "", + name: "Windows 8".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Win7", WootheeResult { - name: "Windows 7", - browser_type: "os", - category: "pc", - os: "", + name: "Windows 7".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("WinVista", WootheeResult { - name: "Windows Vista", - browser_type: "os", - category: "pc", - os: "", + name: "Windows Vista".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("WinXP", WootheeResult { - name: "Windows XP", - browser_type: "os", - category: "pc", - os: "", + name: "Windows XP".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Win2000", WootheeResult { - name: "Windows 2000", - browser_type: "os", - category: "pc", - os: "", + name: "Windows 2000".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("WinNT4", WootheeResult { - name: "Windows NT 4.0", - browser_type: "os", - category: "pc", - os: "", + name: "Windows NT 4.0".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("WinMe", WootheeResult { - name: "Windows Me", - browser_type: "os", - category: "pc", - os: "", + name: "Windows Me".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Win98", WootheeResult { - name: "Windows 98", - browser_type: "os", - category: "pc", - os: "", + name: "Windows 98".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Win95", WootheeResult { - name: "Windows 95", - browser_type: "os", - category: "pc", - os: "", + name: "Windows 95".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("WinPhone", WootheeResult { - name: "Windows Phone OS", - browser_type: "os", - category: "smartphone", - os: "", + name: "Windows Phone OS".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("WinCE", WootheeResult { - name: "Windows CE", - browser_type: "os", - category: "smartphone", - os: "", + name: "Windows CE".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("OSX", WootheeResult { - name: "Mac OSX", - browser_type: "os", - category: "pc", - os: "", + name: "Mac OSX".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("MacOS", WootheeResult { - name: "Mac OS Classic", - browser_type: "os", - category: "pc", - os: "", + name: "Mac OS Classic".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Linux", WootheeResult { - name: "Linux", - browser_type: "os", - category: "pc", - os: "", + name: "Linux".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("BSD", WootheeResult { - name: "BSD", - browser_type: "os", - category: "pc", - os: "", + name: "BSD".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("ChromeOS", WootheeResult { - name: "ChromeOS", - browser_type: "os", - category: "pc", - os: "", + name: "ChromeOS".to_string(), + browser_type: "os".to_string(), + category: "pc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Android", WootheeResult { - name: "Android", - browser_type: "os", - category: "smartphone", - os: "", + name: "Android".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("iPhone", WootheeResult { - name: "iPhone", - browser_type: "os", - category: "smartphone", - os: "", + name: "iPhone".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("iPad", WootheeResult { - name: "iPad", - browser_type: "os", - category: "smartphone", - os: "", + name: "iPad".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("iPod", WootheeResult { - name: "iPod", - browser_type: "os", - category: "smartphone", - os: "", + name: "iPod".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("iOS", WootheeResult { - name: "iOS", - browser_type: "os", - category: "smartphone", - os: "", + name: "iOS".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("FirefoxOS", WootheeResult { - name: "Firefox OS", - browser_type: "os", - category: "smartphone", - os: "", + name: "Firefox OS".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("BlackBerry", WootheeResult { - name: "BlackBerry", - browser_type: "os", - category: "smartphone", - os: "", + name: "BlackBerry".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("BlackBerry10", WootheeResult { - name: "BlackBerry 10", - browser_type: "os", - category: "smartphone", - os: "", + name: "BlackBerry 10".to_string(), + browser_type: "os".to_string(), + category: "smartphone".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("docomo", WootheeResult { - name: "docomo", - browser_type: "full", - category: "mobilephone", - os: "docomo", + name: "docomo".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "docomo".to_string(), os_version: "".to_string(), - vendor: "docomo", + vendor: "docomo".to_string(), version: "".to_string(), }); dataset.insert("au", WootheeResult { - name: "au by KDDI", - browser_type: "full", - category: "mobilephone", - os: "au", + name: "au by KDDI".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "au".to_string(), os_version: "".to_string(), - vendor: "au", + vendor: "au".to_string(), version: "".to_string(), }); dataset.insert("SoftBank", WootheeResult { - name: "SoftBank Mobile", - browser_type: "full", - category: "mobilephone", - os: "SoftBank", + name: "SoftBank Mobile".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "SoftBank".to_string(), os_version: "".to_string(), - vendor: "SoftBank", + vendor: "SoftBank".to_string(), version: "".to_string(), }); dataset.insert("willcom", WootheeResult { - name: "WILLCOM", - browser_type: "full", - category: "mobilephone", - os: "WILLCOM", + name: "WILLCOM".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "WILLCOM".to_string(), os_version: "".to_string(), - vendor: "WILLCOM", + vendor: "WILLCOM".to_string(), version: "".to_string(), }); dataset.insert("jig", WootheeResult { - name: "jig browser", - browser_type: "full", - category: "mobilephone", - os: "jig", + name: "jig browser".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "jig".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("emobile", WootheeResult { - name: "emobile", - browser_type: "full", - category: "mobilephone", - os: "emobile", + name: "emobile".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "emobile".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("SymbianOS", WootheeResult { - name: "SymbianOS", - browser_type: "full", - category: "mobilephone", - os: "SymbianOS", + name: "SymbianOS".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "SymbianOS".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("MobileTranscoder", WootheeResult { - name: "Mobile Transcoder", - browser_type: "full", - category: "mobilephone", - os: "Mobile Transcoder", + name: "Mobile Transcoder".to_string(), + browser_type: "full".to_string(), + category: "mobilephone".to_string(), + os: "Mobile Transcoder".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Nintendo3DS", WootheeResult { - name: "Nintendo 3DS", - browser_type: "full", - category: "appliance", - os: "Nintendo 3DS", + name: "Nintendo 3DS".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "Nintendo 3DS".to_string(), os_version: "".to_string(), - vendor: "Nintendo", + vendor: "Nintendo".to_string(), version: "".to_string(), }); dataset.insert("NintendoDSi", WootheeResult { - name: "Nintendo DSi", - browser_type: "full", - category: "appliance", - os: "Nintendo DSi", + name: "Nintendo DSi".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "Nintendo DSi".to_string(), os_version: "".to_string(), - vendor: "Nintendo", + vendor: "Nintendo".to_string(), version: "".to_string(), }); dataset.insert("NintendoWii", WootheeResult { - name: "Nintendo Wii", - browser_type: "full", - category: "appliance", - os: "Nintendo Wii", + name: "Nintendo Wii".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "Nintendo Wii".to_string(), os_version: "".to_string(), - vendor: "Nintendo", + vendor: "Nintendo".to_string(), version: "".to_string(), }); dataset.insert("NintendoWiiU", WootheeResult { - name: "Nintendo Wii U", - browser_type: "full", - category: "appliance", - os: "Nintendo Wii U", + name: "Nintendo Wii U".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "Nintendo Wii U".to_string(), os_version: "".to_string(), - vendor: "Nintendo", + vendor: "Nintendo".to_string(), version: "".to_string(), }); dataset.insert("PSP", WootheeResult { - name: "PlayStation Portable", - browser_type: "full", - category: "appliance", - os: "PlayStation Portable", + name: "PlayStation Portable".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "PlayStation Portable".to_string(), os_version: "".to_string(), - vendor: "Sony", + vendor: "Sony".to_string(), version: "".to_string(), }); dataset.insert("PSVita", WootheeResult { - name: "PlayStation Vita", - browser_type: "full", - category: "appliance", - os: "PlayStation Vita", + name: "PlayStation Vita".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "PlayStation Vita".to_string(), os_version: "".to_string(), - vendor: "Sony", + vendor: "Sony".to_string(), version: "".to_string(), }); dataset.insert("PS3", WootheeResult { - name: "PlayStation 3", - browser_type: "full", - category: "appliance", - os: "PlayStation 3", + name: "PlayStation 3".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "PlayStation 3".to_string(), os_version: "".to_string(), - vendor: "Sony", + vendor: "Sony".to_string(), version: "".to_string(), }); dataset.insert("PS4", WootheeResult { - name: "PlayStation 4", - browser_type: "full", - category: "appliance", - os: "PlayStation 4", + name: "PlayStation 4".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "PlayStation 4".to_string(), os_version: "".to_string(), - vendor: "Sony", + vendor: "Sony".to_string(), version: "".to_string(), }); dataset.insert("Xbox360", WootheeResult { - name: "Xbox 360", - browser_type: "full", - category: "appliance", - os: "Xbox 360", + name: "Xbox 360".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "Xbox 360".to_string(), os_version: "".to_string(), - vendor: "Microsoft", + vendor: "Microsoft".to_string(), version: "".to_string(), }); dataset.insert("XboxOne", WootheeResult { - name: "Xbox One", - browser_type: "full", - category: "appliance", - os: "Xbox One", + name: "Xbox One".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "Xbox One".to_string(), os_version: "".to_string(), - vendor: "Microsoft", + vendor: "Microsoft".to_string(), version: "".to_string(), }); dataset.insert("DigitalTV", WootheeResult { - name: "InternetTVBrowser", - browser_type: "full", - category: "appliance", - os: "DigitalTV", + name: "InternetTVBrowser".to_string(), + browser_type: "full".to_string(), + category: "appliance".to_string(), + os: "DigitalTV".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("SafariRSSReader", WootheeResult { - name: "Safari RSSReader", - browser_type: "full", - category: "misc", - os: "", + name: "Safari RSSReader".to_string(), + browser_type: "full".to_string(), + category: "misc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Apple", + vendor: "Apple".to_string(), version: "".to_string(), }); dataset.insert("GoogleDesktop", WootheeResult { - name: "Google Desktop", - browser_type: "full", - category: "misc", - os: "", + name: "Google Desktop".to_string(), + browser_type: "full".to_string(), + category: "misc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Google", + vendor: "Google".to_string(), version: "".to_string(), }); dataset.insert("WindowsRSSReader", WootheeResult { - name: "Windows RSSReader", - browser_type: "full", - category: "misc", - os: "", + name: "Windows RSSReader".to_string(), + browser_type: "full".to_string(), + category: "misc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "Microsoft", + vendor: "Microsoft".to_string(), version: "".to_string(), }); dataset.insert("VariousRSSReader", WootheeResult { - name: "RSSReader", - browser_type: "full", - category: "misc", - os: "", + name: "RSSReader".to_string(), + browser_type: "full".to_string(), + category: "misc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("HTTPLibrary", WootheeResult { - name: "HTTP Library", - browser_type: "full", - category: "misc", - os: "", + name: "HTTP Library".to_string(), + browser_type: "full".to_string(), + category: "misc".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("GoogleBot", WootheeResult { - name: "Googlebot", - browser_type: "full", - category: "crawler", - os: "", + name: "Googlebot".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("GoogleBotMobile", WootheeResult { - name: "Googlebot Mobile", - browser_type: "full", - category: "crawler", - os: "", + name: "Googlebot Mobile".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("GoogleMediaPartners", WootheeResult { - name: "Google Mediapartners", - browser_type: "full", - category: "crawler", - os: "", + name: "Google Mediapartners".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("GoogleFeedFetcher", WootheeResult { - name: "Google Feedfetcher", - browser_type: "full", - category: "crawler", - os: "", + name: "Google Feedfetcher".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("GoogleAppEngine", WootheeResult { - name: "Google AppEngine", - browser_type: "full", - category: "crawler", - os: "", + name: "Google AppEngine".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("GoogleWebPreview", WootheeResult { - name: "Google Web Preview", - browser_type: "full", - category: "crawler", - os: "", + name: "Google Web Preview".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("YahooSlurp", WootheeResult { - name: "Yahoo! Slurp", - browser_type: "full", - category: "crawler", - os: "", + name: "Yahoo! Slurp".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("YahooJP", WootheeResult { - name: "Yahoo! Japan", - browser_type: "full", - category: "crawler", - os: "", + name: "Yahoo! Japan".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("YahooPipes", WootheeResult { - name: "Yahoo! Pipes", - browser_type: "full", - category: "crawler", - os: "", + name: "Yahoo! Pipes".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Baiduspider", WootheeResult { - name: "Baiduspider", - browser_type: "full", - category: "crawler", - os: "", + name: "Baiduspider".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("msnbot", WootheeResult { - name: "msnbot", - browser_type: "full", - category: "crawler", - os: "", + name: "msnbot".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("bingbot", WootheeResult { - name: "bingbot", - browser_type: "full", - category: "crawler", - os: "", + name: "bingbot".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("BingPreview", WootheeResult { - name: "BingPreview", - browser_type: "full", - category: "crawler", - os: "", + name: "BingPreview".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Yeti", WootheeResult { - name: "Naver Yeti", - browser_type: "full", - category: "crawler", - os: "", + name: "Naver Yeti".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("FeedBurner", WootheeResult { - name: "Google FeedBurner", - browser_type: "full", - category: "crawler", - os: "", + name: "Google FeedBurner".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("facebook", WootheeResult { - name: "facebook", - browser_type: "full", - category: "crawler", - os: "", + name: "facebook".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("twitter", WootheeResult { - name: "twitter", - browser_type: "full", - category: "crawler", - os: "", + name: "twitter".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("trendictionbot", WootheeResult { - name: "trendiction", - browser_type: "full", - category: "crawler", - os: "", + name: "trendiction".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("mixi", WootheeResult { - name: "mixi", - browser_type: "full", - category: "crawler", - os: "", + name: "mixi".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("IndyLibrary", WootheeResult { - name: "Indy Library", - browser_type: "full", - category: "crawler", - os: "", + name: "Indy Library".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("ApplePubSub", WootheeResult { - name: "Apple iCloud", - browser_type: "full", - category: "crawler", - os: "", + name: "Apple iCloud".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Genieo", WootheeResult { - name: "Genieo Web Filter", - browser_type: "full", - category: "crawler", - os: "", + name: "Genieo Web Filter".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("topsyButterfly", WootheeResult { - name: "topsy Butterfly", - browser_type: "full", - category: "crawler", - os: "", + name: "topsy Butterfly".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("rogerbot", WootheeResult { - name: "SeoMoz rogerbot", - browser_type: "full", - category: "crawler", - os: "", + name: "SeoMoz rogerbot".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("AhrefsBot", WootheeResult { - name: "ahref AhrefsBot", - browser_type: "full", - category: "crawler", - os: "", + name: "ahref AhrefsBot".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("radian6", WootheeResult { - name: "salesforce radian6", - browser_type: "full", - category: "crawler", - os: "", + name: "salesforce radian6".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("Hatena", WootheeResult { - name: "Hatena", - browser_type: "full", - category: "crawler", - os: "", + name: "Hatena".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("goo", WootheeResult { - name: "goo", - browser_type: "full", - category: "crawler", - os: "", + name: "goo".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("livedoorFeedFetcher", WootheeResult { - name: "livedoor FeedFetcher", - browser_type: "full", - category: "crawler", - os: "", + name: "livedoor FeedFetcher".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); dataset.insert("VariousCrawler", WootheeResult { - name: "misc crawler", - browser_type: "full", - category: "crawler", - os: "", + name: "misc crawler".to_string(), + browser_type: "full".to_string(), + category: "crawler".to_string(), + os: "".to_string(), os_version: "".to_string(), - vendor: "", + vendor: "".to_string(), version: "".to_string(), }); diff --git a/src/parser.rs b/src/parser.rs index f3f6987..d5fee1d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -53,44 +53,44 @@ lazy_static! { } #[derive(Debug, Default)] -pub struct WootheeResult<'a> { - pub name: &'a str, - pub category: &'a str, - pub os: &'a str, +pub struct WootheeResult { + pub name: String, + pub category: String, + pub os: String, pub os_version: String, - pub browser_type: &'a str, + pub browser_type: String, pub version: String, - pub vendor: &'a str, + pub vendor: String, } -impl<'a> WootheeResult<'a> { - pub fn new() -> WootheeResult<'a> { +impl WootheeResult { + pub fn new() -> WootheeResult { WootheeResult { - name: VALUE_UNKNOWN, - category: VALUE_UNKNOWN, - os: VALUE_UNKNOWN, + name: VALUE_UNKNOWN.to_string(), + category: VALUE_UNKNOWN.to_string(), + os: VALUE_UNKNOWN.to_string(), os_version: VALUE_UNKNOWN.to_string(), - browser_type: VALUE_UNKNOWN, + browser_type: VALUE_UNKNOWN.to_string(), version: VALUE_UNKNOWN.to_string(), - vendor: VALUE_UNKNOWN, + vendor: VALUE_UNKNOWN.to_string(), } } - fn populate_with(&mut self, ds: &WootheeResult<'a>) { + fn populate_with(&mut self, ds: &WootheeResult) { if !ds.name.is_empty() { - self.name = ds.name; + self.name = ds.name.clone(); } if !ds.category.is_empty() { - self.category = ds.category; + self.category = ds.category.clone(); } if !ds.os.is_empty() { - self.os = ds.os; + self.os = ds.os.clone(); } if !ds.browser_type.is_empty() { - self.browser_type = ds.browser_type; + self.browser_type = ds.browser_type.clone(); } if !ds.version.is_empty() { @@ -98,7 +98,7 @@ impl<'a> WootheeResult<'a> { } if !ds.vendor.is_empty() { - self.vendor = ds.vendor; + self.vendor = ds.vendor.clone(); } } } @@ -149,7 +149,7 @@ impl Parser { None } - fn populate_dataset<'b>(&'b self, result: &mut WootheeResult<'b>, label: &str) -> bool { + fn populate_dataset(&self, result: &mut WootheeResult, label: &str) -> bool { match self.lookup_dataset(label) { Some(ds) => { result.populate_with(ds); @@ -163,7 +163,7 @@ impl Parser { dataset::DATASET.get(label) } - pub fn try_crawler<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + pub fn try_crawler(&self, agent: &str, result: &mut WootheeResult) -> bool { if self.challenge_google(agent, result) { return true; } @@ -175,7 +175,7 @@ impl Parser { false } - fn try_os<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn try_os(&self, agent: &str, result: &mut WootheeResult) -> bool { if self.challenge_windows(agent, result) { return true; } @@ -207,7 +207,7 @@ impl Parser { false } - fn try_browser<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn try_browser(&self, agent: &str, result: &mut WootheeResult) -> bool { if self.challenge_msie(agent, result) { return true; } @@ -243,7 +243,7 @@ impl Parser { false } - fn try_mobilephone<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn try_mobilephone(&self, agent: &str, result: &mut WootheeResult) -> bool { if self.challenge_docomo(agent, result) { return true; } @@ -267,7 +267,7 @@ impl Parser { false } - fn try_appliance<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn try_appliance(&self, agent: &str, result: &mut WootheeResult) -> bool { if self.challenge_playstation(agent, result) { return true; } @@ -282,7 +282,7 @@ impl Parser { false } - fn try_misc<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn try_misc(&self, agent: &str, result: &mut WootheeResult) -> bool { if self.challenge_desktop_tools(agent, result) { return true; } @@ -290,7 +290,7 @@ impl Parser { false } - fn try_rare_cases<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn try_rare_cases(&self, agent: &str, result: &mut WootheeResult) -> bool { if self.challenge_smartphone_patterns(agent, result) { return true; } @@ -314,7 +314,7 @@ impl Parser { false } - fn challenge_google<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_google(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("Google") { return false; } @@ -350,7 +350,7 @@ impl Parser { false } - fn challenge_crawlers<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_crawlers(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("Yahoo") || agent.contains("help.yahoo.co.jp/help/jp/") || agent.contains("listing.yahoo.co.jp/support/faq/") { if agent.contains("compatible; Yahoo! Slurp") { @@ -461,7 +461,7 @@ impl Parser { false } - fn challenge_msie<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_msie(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("compatible; MSIE") && !agent.contains("Trident/") && !agent.contains("IEMobile") { return false; } @@ -489,7 +489,7 @@ impl Parser { true } - fn challenge_ms_edge<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_ms_edge(&self, agent: &str, result: &mut WootheeResult) -> bool { if !RX_MSEDGE_PATTERN.is_match(agent) { return false; }; @@ -501,7 +501,7 @@ impl Parser { true } - fn challenge_vivaldi<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_vivaldi(&self, agent: &str, result: &mut WootheeResult) -> bool { match RX_VIVALDI_PATTERN.captures(agent) { Some(caps) => { result.version = caps.get(1).unwrap().as_str().to_string(); @@ -518,7 +518,7 @@ impl Parser { true } - fn challenge_firefox_ios<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_firefox_ios(&self, agent: &str, result: &mut WootheeResult) -> bool { match RX_FIREFOX_IOS_PATTERN.captures(agent) { Some(caps) => { result.version = caps.get(1).unwrap().as_str().to_string(); @@ -535,7 +535,7 @@ impl Parser { true } - fn challenge_safari_chrome<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_safari_chrome(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("Chrome") && agent.contains("wv") { return false; } @@ -587,7 +587,7 @@ impl Parser { true } - fn challenge_firefox<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_firefox(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("Firefox/") { return false; } @@ -606,7 +606,7 @@ impl Parser { true } - fn challenge_opera<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_opera(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("Opera") { return false; } @@ -630,7 +630,7 @@ impl Parser { true } - fn challenge_webview<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_webview(&self, agent: &str, result: &mut WootheeResult) -> bool { let version = if RX_WEBVIEW_VERSION_PATTERN.is_match(agent) { match RX_WEBVIEW_VERSION_PATTERN.captures(agent) { Some(caps) => caps.get(1).unwrap().as_str(), @@ -665,7 +665,7 @@ impl Parser { true } - fn challenge_docomo<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_docomo(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("DoCoMo") && !agent.contains(";FOMA;") { return false; } @@ -687,7 +687,7 @@ impl Parser { true } - fn challenge_au<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_au(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("KDDI-") { return false; } @@ -706,7 +706,7 @@ impl Parser { true } - fn challenge_softbank<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_softbank(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("SoftBank") && !agent.contains("Vodafone") && !agent.contains("J-PHONE") { return false; } @@ -725,7 +725,7 @@ impl Parser { true } - fn challenge_willcom<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_willcom(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("WILLCOM") && !agent.contains("DDIPOCKET") { return false; } @@ -744,7 +744,7 @@ impl Parser { true } - fn challenge_misc_mobilephone<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_misc_mobilephone(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("jig browser") { if !self.populate_dataset(result, "jig") { return false; @@ -790,7 +790,7 @@ impl Parser { false } - fn challenge_playstation<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_playstation(&self, agent: &str, result: &mut WootheeResult) -> bool { let mut os_version = ""; let d = if agent.contains("PSP (PlayStation Portable)") { @@ -835,7 +835,7 @@ impl Parser { true } - fn challenge_nintendo<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_nintendo(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("Nintendo 3DS;") { return self.populate_dataset(result, "Nintendo3DS"); } @@ -855,7 +855,7 @@ impl Parser { false } - fn challenge_digital_tv<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_digital_tv(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("InettvBrowser/") { return self.populate_dataset(result, "DigitalTV"); } @@ -863,7 +863,7 @@ impl Parser { false } - fn challenge_windows<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_windows(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("Windows") { return false; } @@ -883,8 +883,8 @@ impl Parser { let caps = RX_WINDOWS_VERSION_PATTERN.captures(agent); if caps.is_none() { - result.category = win.category; - result.os = win.name; + result.category = win.category.clone(); + result.os = win.name.clone(); return true; } @@ -917,8 +917,8 @@ impl Parser { } win = w.unwrap(); - result.category = win.category; - result.os = win.name; + result.category = win.category.clone(); + result.os = win.name.clone(); if !version.is_empty() { result.os_version = version.to_string(); } @@ -926,7 +926,7 @@ impl Parser { true } - fn challenge_osx<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_osx(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("Mac OS X") { return false; } @@ -964,8 +964,8 @@ impl Parser { } } - result.category = data.category; - result.os = data.name; + result.category = data.category.clone(); + result.os = data.name.clone(); if !version.is_empty() { result.os_version = version.to_string(); } @@ -973,7 +973,7 @@ impl Parser { true } - fn challenge_linux<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_linux(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("Linux") { return false; } @@ -994,8 +994,8 @@ impl Parser { } let data = d.unwrap(); - result.category = data.category; - result.os = data.name; + result.category = data.category.clone(); + result.os = data.name.clone(); if !os_version.is_empty() { result.os_version = os_version; } @@ -1003,7 +1003,7 @@ impl Parser { true } - fn challenge_smartphone<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_smartphone(&self, agent: &str, result: &mut WootheeResult) -> bool { let mut os_version = ""; let mut d = if agent.contains("iPhone") { @@ -1058,8 +1058,8 @@ impl Parser { } let data = d.unwrap(); - result.category = data.category; - result.os = data.name; + result.category = data.category.clone(); + result.os = data.name.clone(); if !os_version.is_empty() { result.os_version = os_version.to_string(); } @@ -1067,7 +1067,7 @@ impl Parser { true } - fn challenge_mobilephone<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_mobilephone(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("KDDI-") { let caps = RX_KDDI_PATTERN.captures(agent); if caps.is_some() { @@ -1077,8 +1077,8 @@ impl Parser { return false; } let data = d.unwrap(); - result.category = data.category; - result.os = data.os; + result.category = data.category.clone(); + result.os = data.os.clone(); result.version = term.to_string(); return true; } @@ -1093,8 +1093,8 @@ impl Parser { return false; } let data = d.unwrap(); - result.category = data.category; - result.os = data.os; + result.category = data.category.clone(); + result.os = data.os.clone(); result.version = term.to_string(); return true; } @@ -1106,8 +1106,8 @@ impl Parser { return false; } let data = d.unwrap(); - result.category = data.category; - result.os = data.os; + result.category = data.category.clone(); + result.os = data.os.clone(); return true; } @@ -1128,7 +1128,7 @@ impl Parser { false } - fn challenge_desktop_tools<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_desktop_tools(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("AppleSyndication/") { return self.populate_dataset(result, "SafariRSSReader"); } @@ -1144,7 +1144,7 @@ impl Parser { false } - fn challenge_smartphone_patterns<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_smartphone_patterns(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("CFNetwork/") { // This is like iPhone, but only Category and Name are filled let d = self.lookup_dataset("iOS"); @@ -1153,15 +1153,15 @@ impl Parser { } let data = d.unwrap(); - result.os = data.name; - result.category = data.category; + result.os = data.name.clone(); + result.category = data.category.clone(); return true; } false } - fn challenge_sleipnir<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_sleipnir(&self, agent: &str, result: &mut WootheeResult) -> bool { if !agent.contains("Sleipnir/") { return false; } @@ -1180,13 +1180,13 @@ impl Parser { let win = w.unwrap(); result.version = version.to_string(); - result.category = win.category; - result.os = win.name; + result.category = win.category.clone(); + result.os = win.name.clone(); true } - fn challenge_http_library<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_http_library(&self, agent: &str, result: &mut WootheeResult) -> bool { // TODO: wip let mut version = ""; @@ -1221,7 +1221,7 @@ impl Parser { true } - fn challenge_maybe_rss_reader<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_maybe_rss_reader(&self, agent: &str, result: &mut WootheeResult) -> bool { if RX_MAYBE_RSS_PATTERN.is_match(agent) || agent.to_lowercase().contains("headline-reader") || agent.contains("cococ/") { return self.populate_dataset(result, "VariousRSSReader"); @@ -1230,7 +1230,7 @@ impl Parser { false } - fn challenge_maybe_crawler<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_maybe_crawler(&self, agent: &str, result: &mut WootheeResult) -> bool { if RX_MAYBE_CRAWLER_PATTERN.is_match(agent) || RX_MAYBE_CRAWLER_OTHER.is_match(agent) || agent.contains("ASP-Ranker Feed Crawler") || RX_MAYBE_FEED_PARSER_PATTERN.is_match(agent) || RX_MAYBE_WATCHDOG_PATTERN.is_match(agent) { @@ -1240,15 +1240,15 @@ impl Parser { false } - fn challenge_appliance<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_appliance(&self, agent: &str, result: &mut WootheeResult) -> bool { if agent.contains("Nintendo DSi;") { let d = self.lookup_dataset("NintendoDSi"); if d.is_none() { return false; } let data = d.unwrap(); - result.category = data.category; - result.os = data.os; + result.category = data.category.clone(); + result.os = data.os.clone(); return true; } @@ -1258,15 +1258,15 @@ impl Parser { return false; } let data = d.unwrap(); - result.category = data.category; - result.os = data.os; + result.category = data.category.clone(); + result.os = data.os.clone(); return true; } false } - fn challenge_misc_os<'b>(&'b self, agent: &str, result: &mut WootheeResult<'b>) -> bool { + fn challenge_misc_os(&self, agent: &str, result: &mut WootheeResult) -> bool { let d = if agent.contains("(Win98;") { result.os_version = "98".to_string(); self.lookup_dataset("Win98") @@ -1297,8 +1297,8 @@ impl Parser { } let data = d.unwrap(); - result.category = data.category; - result.os = data.name; + result.category = data.category.clone(); + result.os = data.name.clone(); true } diff --git a/templates/dataset.tmpl b/templates/dataset.tmpl index 821bd23..b7dd7df 100644 --- a/templates/dataset.tmpl +++ b/templates/dataset.tmpl @@ -3,18 +3,18 @@ use std::collections::HashMap; use parser::WootheeResult; lazy_static! { - pub static ref DATASET: HashMap<&'static str, WootheeResult<'static>> = { + pub static ref DATASET: HashMap<&'static str, WootheeResult> = { let mut dataset = HashMap::new(); {% for result in results %} dataset.insert("{{result.label}}", WootheeResult { - name: "{{result.name}}", - browser_type: "{{result.browser_type}}", - category: "{{result.category}}", - os: "{{result.os}}", + name: "{{result.name}}".to_string(), + browser_type: "{{result.browser_type}}".to_string(), + category: "{{result.category}}".to_string(), + os: "{{result.os}}".to_string(), os_version: "{{result.os_version}}".to_string(), - vendor: "{{result.vendor}}", + vendor: "{{result.vendor}}".to_string(), version: "{{result.version}}".to_string(), }); {% endfor %} From aee5e173e86a65c825bc73dd555a45d29efb0db8 Mon Sep 17 00:00:00 2001 From: Hideo Hattori <hattori-h@klab.com> Date: Fri, 2 Feb 2018 14:38:05 +0900 Subject: [PATCH 3/3] add unit test (for #5) --- src/lib.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fcf80c3..a2c43b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,9 +46,25 @@ pub fn is_crawler(agent: &str) -> bool { parser.try_crawler(agent, &mut result) } -#[test] -fn test_is_crawler_smoke() { - assert!(!is_crawler("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")); - assert!(is_crawler("Mozilla/5.0 (compatible; Yahoo! Slurp; \ - http://help.yahoo.com/help/us/ysearch/slurp)")); +#[cfg(test)] +mod tests { + use super::{is_crawler, WootheeResult, Parser}; + + fn get_woothee_result(agent: &str) -> WootheeResult { + Parser::new().parse(agent).expect("fail parse()") + } + + #[test] + fn test_parser_lifetime() { + let agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:21.0) Gecko/20100101 Firefox/21.0"; + let result = get_woothee_result(agent); + assert_eq!(result.name.as_str(), "Firefox"); + } + + #[test] + fn test_is_crawler_smoke() { + assert!(!is_crawler("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")); + assert!(is_crawler("Mozilla/5.0 (compatible; Yahoo! Slurp; \ + http://help.yahoo.com/help/us/ysearch/slurp)")); + } }