PublicSuffix2
A native Rust library for parsing and using Mozilla's Public Suffix List.
This library is a fork of rushmorem/publicsuffix and aims to reach feature parity with the popular Python library python-publicsuffix2
The Public Suffix List is a collection of all TLDs (Top-Level Domains) and other domains under which Internet users can directly register names. This library allows you to determine the "public suffix" part of a domain name.
Features
- Find the Public Suffix (TLD/eTLD): Extract the effective Top-Level Domain from any hostname.
- Find the Second-Level Domain (SLD/eTLD + 1): Extract the main, registrable part of a domain.
- Configurable Normalization: Control over lowercasing, handling of trailing dots, and IDNA (Punycode) conversion.
- ICANN and Private Rules: Filter matches to include only ICANN-managed TLDs or also include privately-managed domains (e.g.,
github.io). - Wildcard and Exception Rule Support: Correctly handles complex rules like
*.ckand!www.ck. - IDN and Punycode: Works seamlessly with both Unicode (e.g.,
食狮.中国) and Punycode (xn--fiqs8s.xn--fiq228c) domain names. - High Performance: Uses a trie data structure for fast lookups.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Usage
First, you need a copy of the Public Suffix List. You can download it from the official site.
Basic Example
use ;
// Load the PSL data into the library.
// It's recommended to do this once and reuse the `List` object.
const PSL: &str = include_str!;
Advanced Options
You can customize matching behavior using MatchOpts and Normalizer.
use ;
const PSL: &str = include_str!;
License
This project is licensed under the MIT License. See the LICENSE file for details.