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

no-std psl

Extract root domain and suffix from a domain name

89 releases (stable)

new 2.0.56 Oct 17, 2021
2.0.52 Sep 30, 2021
2.0.40 Jul 27, 2021
2.0.15 Mar 31, 2021
0.0.2 Jan 8, 2017

#46 in No standard library

Download history 2340/week @ 2021-07-02 2815/week @ 2021-07-09 3463/week @ 2021-07-16 2767/week @ 2021-07-23 3245/week @ 2021-07-30 2727/week @ 2021-08-06 2365/week @ 2021-08-13 3070/week @ 2021-08-20 3641/week @ 2021-08-27 2890/week @ 2021-09-03 3504/week @ 2021-09-10 3921/week @ 2021-09-17 3589/week @ 2021-09-24 3321/week @ 2021-10-01 2314/week @ 2021-10-08 2262/week @ 2021-10-15

13,199 downloads per month
Used in 7 crates (2 directly)


87K 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.");