pub struct Bots { /* private fields */ }Expand description
Wrapper struct to maintain bot regular expression patterns
§Example
use isbot::Bots;
let bots = Bots::default();Implementations§
Source§impl Bots
impl Bots
Sourcepub fn new(bot_entries: &str) -> Self
pub fn new(bot_entries: &str) -> Self
Constructs a new instance with bot user-agent regular expression entries delimited by a newline
All user-agent regular expressions are converted to lowercase.
§Example
use isbot::Bots;
let custom_user_agent_patterns = r#"
^Googlebot-Image/
bingpreview/"#;
let bots = Bots::new(custom_user_agent_patterns);
assert!(bots.is_bot("Googlebot-Image/1.0"));
assert!(bots.is_bot("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b"));
assert!(!bots.is_bot("Googlebot"));Sourcepub fn is_bot(&self, user_agent: &str) -> bool
pub fn is_bot(&self, user_agent: &str) -> bool
Returns true the user-agent is a known bot.
The user-agent comparison is done using lowercase.
§Example
use isbot::Bots;
let bots = Bots::default();
assert!(bots.is_bot("Googlebot/2.1 (+http://www.google.com/bot.html)"));
assert!(!bots.is_bot("Dalvik/2.1.0 (Linux; U; Android 8.0.0; SM-G930F Build/R16NW)"));Sourcepub fn append(&mut self, bots: &[&str])
pub fn append(&mut self, bots: &[&str])
Appends bot user-agent regular expressions patterns.
Duplicates are ignored.
§Example
use isbot::Bots;
let mut bots = Bots::default();
assert!(!bots.is_bot("Mozilla/5.0 (CustomNewTestB0T /1.2)"));
bots.append(&[r"CustomNewTestB0T\s/\d\.\d"]);
assert!(bots.is_bot("Mozilla/5.0 (CustomNewTestB0T /1.2)"));
let new_bot_patterns = vec!["GoogleMetaverse", "^Special/"];
bots.append(&new_bot_patterns);
assert!(bots.is_bot("Mozilla/5.0 (GoogleMetaverse/1.0)"));Sourcepub fn remove(&mut self, bots: &[&str])
pub fn remove(&mut self, bots: &[&str])
Removes bot user-agent regular expressions.
§Example
use isbot::Bots;
let mut bots = Bots::default();
assert!(bots.is_bot("Chrome-Lighthouse"));
bots.remove(&["Chrome-Lighthouse"]);
assert!(!bots.is_bot("Chrome-Lighthouse"));
let bot_patterns_to_remove = vec!["bingpreview/", "Google Favicon"];
bots.remove(&bot_patterns_to_remove);
assert!(!bots.is_bot("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b"));
assert!(!bots.is_bot("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36 Google Favicon"));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bots
impl RefUnwindSafe for Bots
impl Send for Bots
impl Sync for Bots
impl Unpin for Bots
impl UnwindSafe for Bots
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