2 stable releases

1.0.1 Jan 10, 2024
1.0.0 Feb 24, 2023

#10 in #suffix

Download history 48/week @ 2024-05-26 57/week @ 2024-06-02 48/week @ 2024-06-09 24/week @ 2024-06-16 64/week @ 2024-06-23 26/week @ 2024-06-30 53/week @ 2024-07-07 38/week @ 2024-07-14 49/week @ 2024-07-21 70/week @ 2024-07-28 17/week @ 2024-08-04 90/week @ 2024-08-11 14/week @ 2024-08-18 78/week @ 2024-08-25 27/week @ 2024-09-01 10/week @ 2024-09-08

129 downloads per month

MIT license

45KB
437 lines

dns_name

Robust domain name parsing using the Public Suffix List

This library allows you to easily and accurately parse any given domain name.

let list = List::from_path("suffix-list.txt").unwrap();

let domain = list.parse_dns_name("www.example.com")?;
assert_eq!(domain.name(), "www.example.com");
assert_eq!(domain.rname(), "moc.elpmaxe.www");
assert_eq!(domain.root(), Some("example.com"));
assert_eq!(domain.suffix(), Some("com"));
assert_eq!(domain.registrable(), Some("example"));

// 2-level TLD
let domain = list.parse_dns_name("wWw.BlUeCaTnEtWoRkS.Uk.CoM.")?;
assert_eq!(domain.name(), "www.bluecatnetworks.uk.com.");
assert_eq!(domain.rname(), ".moc.ku.skrowtentaceulb.www");
assert_eq!(domain.root(), Some("bluecatnetworks.uk.com."));
assert_eq!(domain.suffix(), Some("uk.com."));
assert_eq!(domain.registrable(), Some("bluecatnetworks"));

// the root name
let domain = list.parse_dns_name(".")?;
assert_eq!(domain.name(), ".");
assert_eq!(domain.rname(), ".");
assert_eq!(domain.root(), None);
assert_eq!(domain.suffix(), None);
assert_eq!(domain.registrable(), None);

Dependencies

~5.5MB
~124K SLoC