2 releases

0.1.1 Mar 31, 2024
0.1.0 Mar 30, 2024

#2 in #exclusion

Download history 2/week @ 2024-08-23 1/week @ 2024-08-30 14/week @ 2024-09-20 20/week @ 2024-09-27 3/week @ 2024-10-04

65 downloads per month

MIT license

27KB
592 lines

Roboto: Parse and use robots.txt files

Roboto provides a type-safe way to parse and use robots.txt files. It is based on the Robots Exclusion Protocol and is used to approximately try control the behavior of web crawlers and other web robots.

Installation

Add this to your Cargo.toml:

[dependencies]
roboto = "0.1"

Usage

use roboto::Robots;

let robots = r#"
User-agent: *
Disallow: /private
Disallow: /tmp
"#.parse::<Robots>().unwrap();

let user_agent = "googlebot".parse().unwrap();

assert_eq!(robots.is_allowed(&user_agent, "/public"), true);

lib.rs:

Parsing and applying robots.txt files.

Examples

use roboto::Robots;

let robots = r#"
User-agent: *
Disallow: /
"#.parse::<Robots>().unwrap();

assert!(!robots.is_allowed(&"googlebot".parse().unwrap(), "/"));
assert!(robots.is_allowed(&"googlebot".parse().unwrap(), "/robots.txt"));
assert!(!robots.is_allowed(&"googlebot".parse().unwrap(), "/foo/bar"));

References

Dependencies

~125KB