Crate publicsuffix [] [src]

The Public Suffix List Client Library

This library allows you to easily and accurately validate or break down any given domain name.

Examples

extern crate publicsuffix;

use publicsuffix::List;

fn main() {
    let list = List::fetch().unwrap();

    let domain = list.parse_domain("www.example.com").unwrap();
    let tld = domain.root_domain().unwrap();
    assert_eq!(tld, &String::from("example.com"));

    let domain = list.parse_domain("www.食狮.中国").unwrap();
    let tld = domain.root_domain().unwrap();
    assert_eq!(tld, &String::from("食狮.中国"));

    let domain = list.parse_domain("www.xn--85x722f.xn--55qx5d.cn").unwrap();
    let tld = domain.root_domain().unwrap();
    assert_eq!(tld, &String::from("xn--85x722f.xn--55qx5d.cn"));

    let domain = list.parse_domain("a.b.domain.biz").unwrap();
    let suffix = domain.suffix().unwrap();
    assert_eq!(suffix, &String::from("biz"));

    let domain = list.parse_domain("a.b.example.uk.com").unwrap();
    let suffix = domain.suffix().unwrap();
    assert_eq!(suffix, &String::from("uk.com"));
}

Modules

errors

Errors returned by this library

Structs

Domain

Holds information about a particular domain

List

Stores the public suffix list