pub struct KeywordClassifier<T> { /* private fields */ }Expand description
Aho-Corasick based keyword classifier.
Given a set of rules (keywords, classification) ordered by priority,
classify scans the input in a single O(n) pass and
returns the classification of the first (highest-priority) keyword
that matches as a substring. All matching is case-insensitive – keywords
are lowercased at insert time and input bytes are lowercased inline during
the scan (no allocation).
§Example
use spider_browser::retry::keyword_classifier::KeywordClassifier;
let classifier: KeywordClassifier<&str> = KeywordClassifier::new(&[
(&["blocked", "captcha", "403"], "blocked"),
(&["timeout", "err_connection_reset"], "transient"),
]);
assert_eq!(classifier.classify("Error 403 Forbidden"), Some(&"blocked"));
assert_eq!(classifier.classify("ERR_CONNECTION_RESET"), Some(&"transient"));
assert_eq!(classifier.classify("all good"), None);Implementations§
Source§impl<T: Clone> KeywordClassifier<T>
impl<T: Clone> KeywordClassifier<T>
Auto Trait Implementations§
impl<T> Freeze for KeywordClassifier<T>
impl<T> RefUnwindSafe for KeywordClassifier<T>where
T: RefUnwindSafe,
impl<T> Send for KeywordClassifier<T>where
T: Send,
impl<T> Sync for KeywordClassifier<T>where
T: Sync,
impl<T> Unpin for KeywordClassifier<T>where
T: Unpin,
impl<T> UnsafeUnpin for KeywordClassifier<T>
impl<T> UnwindSafe for KeywordClassifier<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more