Skip to main content

Crate use_domain

Crate use_domain 

Source
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 true when the domain has more than two labels.
is_ascii_domain
Returns true when the normalized domain is ASCII.
is_valid_domain
Returns true when the input is a valid ASCII domain name with at least one dot.
is_valid_hostname
Returns true when 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.