Expand description
§use-domain
use-domain provides lightweight helpers for validating, normalizing, and inspecting domain names and hostnames.
Experimental: this crate is below 0.3.0 and the API may change.
§Example Usage
use use_domain::{normalize_domain, root_domain_guess, split_domain_labels};
assert_eq!(normalize_domain("WWW.Example.com."), Some("www.example.com".to_string()));
assert_eq!(split_domain_labels("api.example.com"), vec!["api", "example", "com"]);
assert_eq!(root_domain_guess("api.example.com"), Some("example.com".to_string()));§Scope
- Domain and hostname validation.
- Domain normalization and label splitting.
- Small inspection helpers such as depth and subdomain checks.
§Non-goals
- Complete public suffix list support.
- IDNA conversion.
- DNS lookup.
- Certificate validation.
§License
Licensed under MIT OR Apache-2.0.
Structs§
- Domain
- Stores a normalized domain name and its labels.
Functions§
- domain_
depth - Returns the number of labels in a valid domain name.
- has_
subdomain - Returns
truewhen the domain has more than two labels. - is_
ascii_ domain - Returns
truewhen the normalized domain is ASCII. - is_
valid_ domain - Returns
truewhen the input is a valid ASCII domain name with at least one dot. - is_
valid_ hostname - Returns
truewhen the input is a valid ASCII hostname or domain name. - normalize_
domain - Normalizes a valid domain name.
- root_
domain_ guess - Returns a naive root-domain guess based on the last two labels.
- split_
domain_ labels - Splits a valid domain name into labels.