Crate publicsuffix [−] [src]
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; let list = List::fetch()?; // 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")); // 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());
Reexports
pub use errors::Result; |
pub use errors::Error; |
Modules
errors |
Errors returned by this library |
Structs
Domain |
Holds information about a particular domain |
List |
Stores the public suffix list |