Struct RobotsMatcher

Source
pub struct RobotsMatcher<S: RobotsMatchStrategy> { /* private fields */ }
Expand description

RobotsMatcher - matches robots.txt against URLs.

The Matcher uses a default match strategy for Allow/Disallow patterns which is the official way of Google crawler to match robots.txt. It is also possible to provide a custom match strategy.

The entry point for the user is to call one of the allowed_by_robots methods that return directly if a URL is being allowed according to the robots.txt and the crawl agent. The RobotsMatcher can be re-used for URLs/robots.txt but is not thread-safe.

Implementations§

Source§

impl<'a, S: RobotsMatchStrategy> RobotsMatcher<S>

Source

pub fn allowed_by_robots( &mut self, robots_body: &str, user_agents: Vec<&str>, url: &str, ) -> bool
where Self: RobotsParseHandler,

Returns true if ‘url’ is allowed to be fetched by any member of the “user_agents” vector. ‘url’ must be %-encoded according to RFC3986.

Source

pub fn one_agent_allowed_by_robots( &mut self, robots_txt: &str, user_agent: &str, url: &str, ) -> bool
where Self: RobotsParseHandler,

Do robots check for ‘url’ when there is only one user agent. ‘url’ must be %-encoded according to RFC3986.

Source

pub fn is_valid_user_agent_to_obey(user_agent: &str) -> bool

Verifies that the given user agent is valid to be matched against robots.txt. Valid user agent strings only contain the characters [a-zA-Z_-].

Source

pub fn matching_line(&self) -> u32

Returns the line that matched or 0 if none matched.

Trait Implementations§

Source§

impl<S: Default + RobotsMatchStrategy> Default for RobotsMatcher<S>

Source§

fn default() -> RobotsMatcher<S>

Returns the “default value” for a type. Read more
Source§

impl<S: RobotsMatchStrategy> RobotsParseHandler for RobotsMatcher<S>

Source§

fn handle_robots_start(&mut self)

Source§

fn handle_robots_end(&mut self)

Source§

fn handle_user_agent(&mut self, _line_num: u32, user_agent: &str)

Source§

fn handle_allow(&mut self, line_num: u32, value: &str)

Source§

fn handle_disallow(&mut self, line_num: u32, value: &str)

Source§

fn handle_sitemap(&mut self, _line_num: u32, _value: &str)

Source§

fn handle_unknown_action(&mut self, _line_num: u32, _action: &str, _value: &str)

Any other unrecognized name/value pairs.

Auto Trait Implementations§

§

impl<S> Freeze for RobotsMatcher<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for RobotsMatcher<S>
where S: RefUnwindSafe,

§

impl<S> Send for RobotsMatcher<S>
where S: Send,

§

impl<S> Sync for RobotsMatcher<S>
where S: Sync,

§

impl<S> Unpin for RobotsMatcher<S>
where S: Unpin,

§

impl<S> UnwindSafe for RobotsMatcher<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.