Skip to main content

Crate tld

Crate tld 

Source
Expand description

§tld

A compile-time static perfect hash map of all official top-level domains (TLDs), automatically synchronized from the IANA Root Zone Database.

§Features

  • Zero Runtime Allocation / O(1) Lookups: Backed by phf::Set.
  • no_std Compatible: Can be used in embedded or no_std crates.
  • Case-insensitive helper: exist_case_insensitive for convenience.

§Example

use tld::{exist, exist_case_insensitive, TLD};

// Fast exact lookup (requires lowercase ASCII string)
assert!(exist("com"));
assert!(exist("org"));
assert!(exist("io"));
assert!(exist("uk"));
assert!(!exist("invalidtld"));

// Case-insensitive lookup helper
assert!(exist_case_insensitive("COM"));
assert!(exist_case_insensitive("Xn--FIQS8S"));

// Direct access to the compile-time phf::Set
assert!(TLD.contains("net"));
assert!(TLD.len() > 1400);

Statics§

TLD
Top level domain static map, list is obtained from iana.org.

Functions§

exist
Checks if the given ASCII lowercase string is a valid Top-Level Domain (TLD) in the official IANA database.
exist_case_insensitive
Checks if the given string is a valid Top-Level Domain (TLD), ignoring ASCII case.