#tld #gtld #cctld #psl #no-std

no-std psl

A native library for Mozilla’s Public Suffix List

52 releases (30 stable)

new 2.0.19 Apr 18, 2021
2.0.15 Mar 31, 2021
1.0.9 Mar 12, 2021
0.7.0 Feb 27, 2021
0.0.2 Jan 8, 2017

#48 in No standard library

Download history 1159/week @ 2020-12-25 1095/week @ 2021-01-01 1012/week @ 2021-01-08 940/week @ 2021-01-15 1551/week @ 2021-01-22 1527/week @ 2021-01-29 1062/week @ 2021-02-05 1153/week @ 2021-02-12 1155/week @ 2021-02-19 1681/week @ 2021-02-26 1548/week @ 2021-03-05 1695/week @ 2021-03-12 2021/week @ 2021-03-19 1461/week @ 2021-03-26 1658/week @ 2021-04-02 1728/week @ 2021-04-09

6,492 downloads per month
Used in 4 crates (via addr)

MIT/Apache

2MB
86K SLoC

PSL

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:

[dependencies]
psl = "2"

Examples

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

Dependencies