Expand description
Robust domain name parsing using the Public Suffix List
This library allows you to easily and accurately parse any given domain name.
§Examples
extern crate publicsuffix;
use publicsuffix::List;
// Fetch the list from the official URL,
let list = List::fetch()?;
// from your own URL
let list = List::from_url("https://example.com/path/to/public_suffix_list.dat")?;
// or from a local file.
let list = List::from_path("/path/to/public_suffix_list.dat")?;
// Using the list you can find out the root domain
// or extension of any given domain name
let domain = list.parse_domain("www.example.com")?;
assert_eq!(domain.root(), Some("example.com"));
assert_eq!(domain.suffix(), Some("com"));
let domain = list.parse_domain("www.食狮.中国")?;
assert_eq!(domain.root(), Some("食狮.中国"));
assert_eq!(domain.suffix(), Some("中国"));
let domain = list.parse_domain("www.xn--85x722f.xn--55qx5d.cn")?;
assert_eq!(domain.root(), Some("xn--85x722f.xn--55qx5d.cn"));
assert_eq!(domain.suffix(), Some("xn--55qx5d.cn"));
let domain = list.parse_domain("a.b.example.uk.com")?;
assert_eq!(domain.root(), Some("example.uk.com"));
assert_eq!(domain.suffix(), Some("uk.com"));
let name = list.parse_dns_name("_tcp.example.com.")?;
assert_eq!(name.domain().and_then(|domain| domain.root()), Some("example.com"));
assert_eq!(name.domain().and_then(|domain| domain.suffix()), Some("com"));
// You can also find out if this is an ICANN domain
assert!(!domain.is_icann());
// or a private one
assert!(domain.is_private());
// In any case if the domain's suffix is in the list
// then this is definately a registrable domain name
assert!(domain.has_known_suffix());
Re-exports§
Modules§
- Errors returned by this library
Structs§
- Holds information about a particular DNS name
- Holds information about a particular domain
- Stores the public suffix list
Enums§
- Holds information about a particular host
Constants§
- The official URL of the list
Traits§
- Converts a type into a Url object