Struct texting_robots::Robot

source ·
pub struct Robot {
    pub delay: Option<f32>,
    pub sitemaps: Vec<String>,
    /* private fields */
}

Fields§

§delay: Option<f32>

The delay in seconds between requests. If Crawl-Delay is set in robots.txt it will return Some(f32) and otherwise None.

§sitemaps: Vec<String>

Any sitemaps found in the robots.txt file are added to this vector. According to the robots.txt specification a sitemap found in robots.txt is accessible and available to any bot reading robots.txt.

Implementations§

source§

impl Robot

source

pub fn new(agent: &str, txt: &[u8]) -> Result<Self, Error>

Construct a new Robot object specifically processed for the given user agent. The user agent extracts all relevant rules from robots.txt and stores them internally. If the user agent isn’t found in robots.txt we default to *.

Note: The agent string is lowercased before comparison, as required by the robots.txt specification.

Errors

If there are difficulties parsing, which should be rare as the parser is quite forgiving, then an InvalidRobots error is returned.

source

pub fn allowed(&self, url: &str) -> bool

Check if the given URL is allowed for the agent by robots.txt. This function returns true or false according to the rules in robots.txt.

The provided URL can be absolute or relative depending on user preference.

Example
use texting_robots::Robot;

let r = Robot::new("Ferris", b"Disallow: /secret").unwrap();
assert_eq!(r.allowed("https://example.com/secret"), false);
assert_eq!(r.allowed("/secret"), false);
assert_eq!(r.allowed("/everything-else"), true);

Trait Implementations§

source§

impl Debug for Robot

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Robot

§

impl Send for Robot

§

impl Sync for Robot

§

impl Unpin for Robot

§

impl UnwindSafe for Robot

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.