#tld #no-std #tldextract #domain #publicsuffix

no-std psl

Extract root domain and suffix from a domain name

101 stable releases

new 2.0.90 Jun 30, 2022
2.0.87 Apr 13, 2022
2.0.84 Mar 26, 2022
2.0.65 Dec 14, 2021
0.0.2 Jan 8, 2017

#26 in Web programming

Download history 3388/week @ 2022-03-15 2874/week @ 2022-03-22 3489/week @ 2022-03-29 3775/week @ 2022-04-05 3176/week @ 2022-04-12 3254/week @ 2022-04-19 3241/week @ 2022-04-26 4308/week @ 2022-05-03 5250/week @ 2022-05-10 3491/week @ 2022-05-17 3681/week @ 2022-05-24 4966/week @ 2022-05-31 4125/week @ 2022-06-07 4048/week @ 2022-06-14 3411/week @ 2022-06-21 3430/week @ 2022-06-28

15,911 downloads per month
Used in 24 crates (2 directly)


89K SLoC


A native Rust library for Mozilla's Public Suffix List

CI Publish Latest Version Crates.io downloads Docs Minimum supported Rust version Maintenance License

This library uses Mozilla's Public Suffix List to reliably determine the suffix of a domain name.

It compiles the list down to native Rust code for ultimate speed. This list compilation is done as a separate step by the Publish GitHub Action so the crate still compiles very quickly. The Publish action automatically checks for updates everyday and pushes an updated crate to crates.io if there were any updates in the upstream domain suffixes. This keeps the crate automatically synchronised with the official list.

If you need a dynamic list that can be updated at runtime, though a bit slower, please use the publicsuffix crate instead (which also has optional support for looking up domain names in any case).

Setting Up

Add this crate to your Cargo.toml:

psl = "2"


use psl::{Psl, List};

let suffix = List.suffix(b"www.example.com")?;
assert_eq!(suffix, "com");
assert_eq!(suffix.typ(), Some(Type::Icann));

let domain = List.domain(b"www.example.com")?;
assert_eq!(domain, "example.com");
assert_eq!(domain.suffix(), "com");

let domain = List.domain("www.食狮.中国".as_bytes())?;
assert_eq!(domain, "食狮.中国");
assert_eq!(domain.suffix(), "中国");

let domain = List.domain(b"www.xn--85x722f.xn--55qx5d.cn")?;
assert_eq!(domain, "xn--85x722f.xn--55qx5d.cn");
assert_eq!(domain.suffix(), "xn--55qx5d.cn");

let domain = List.domain(b"a.b.example.uk.com")?;
assert_eq!(domain, "example.uk.com");
assert_eq!(domain.suffix(), "uk.com");

let domain = List.domain(b"_tcp.example.com.")?;
assert_eq!(domain, "example.com.");
assert_eq!(domain.suffix(), "com.");