psl
A native Rust crate that compiles Mozilla's Public Suffix List into code to extract domain suffixes at top speed.
Repository Health
Technical Analysis
psl is a native, no_std Rust library that determines the public suffix and registrable domain of any host using Mozilla’s Public Suffix List. Rather than parsing the list at runtime, it compiles the entire suffix list down to native Rust match code, so lookups are extremely fast and add almost nothing to your compile time.
A GitHub Action rebuilds and republishes the crate whenever the upstream Public Suffix List changes, keeping it automatically synchronised with the official data. For workloads that need a runtime-updatable list instead, the sibling publicsuffix crate is recommended.
What You Get
- A precompiled, always-up-to-date embedding of Mozilla’s Public Suffix List baked into native Rust code
- Simple helper functions (
suffix,domain, and their_strvariants) for extracting suffixes and registrable domains - A
no_std, zero-unsafe implementation that works in constrained and embedded environments - Correct handling of ICANN vs. private suffixes, internationalized (Unicode/punycode) domains, and multi-level suffixes
- An automated publish pipeline that keeps the crate in sync with the upstream suffix list daily
Common Use Cases
- Extracting the registrable domain from a URL or hostname for grouping, deduplication, or display
- Validating and normalizing domains in email, DNS, or web-crawling pipelines
- Building cookie-scoping or same-site logic that must respect public suffix boundaries
- Implementing tldextract-style subdomain/domain/suffix splitting in Rust services
Under The Hood
Architecture - The crate is intentionally thin: src/lib.rs defines a zero-sized List struct implementing the Psl trait from the psl-types dependency, delegating every lookup to a generated list::lookup function. That function lives in src/list.rs, a ~2.5 MB machine-generated file that encodes Mozilla’s entire Public Suffix List as a nested match over domain labels represented as raw byte slices, walking labels right-to-left and returning an Info { len, typ }. The optional helpers feature layers ergonomic suffix/domain wrappers on top of that trait.
Tech Stack - Pure Rust on the 2018 edition with a rustc 1.41+ minimum, #![no_std], and a single runtime dependency (psl-types). Dev/build tooling uses cargo-make (Makefile.toml) to regenerate list.rs, rspec for the conformance tests, and a nightly #![feature(test)] bench harness. Distribution is automated via GitHub Actions that regenerate and publish daily when the upstream list changes.
Code Quality - The hand-written surface is small, idiomatic, and hardened with #![forbid(unsafe_code)]. Correctness is covered by tests/list.rs, which runs the official Public Suffix List tests.txt conformance suite through rspec, plus a fuzz/ target. The bulk of the code (list.rs) is generated and explicitly excluded from manual editing and clippy, which is a reasonable trade-off for this design.
API Design - The public API is minimal and hard to misuse: psl::suffix(b"www.example.com") and psl::domain(...) return Option-wrapped results, with _str variants for &str output. The README’s worked examples (Unicode, punycode, multi-level suffixes) get a new user productive in minutes, and the only real configuration decision is the helpers feature flag.
Used by 2 apps in this directory
Firecrawl
AI Development · Developer Tools
Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.
Stalwart
Collaboration
All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.