pub fn is_valid_hostname(hostname: &str) -> boolExpand description
Validates if a string is a valid hostname according to RFC 1035.
A valid hostname must:
- Be between 1 and 253 characters in length
- Not use reserved top-level domains (.localhost, .internal, .arpa, .local)
- Not be an IPv4 or IPv6 address
- Contain only valid hostname characters (letters, digits, hyphens, dots)
- Have valid DNS labels (no leading/trailing hyphens, max 63 chars per label)
§Arguments
hostname- The hostname string to validate
§Returns
true if the hostname is valid according to RFC 1035, false otherwise
§Examples
use atproto_identity::validation::is_valid_hostname;
// Valid hostnames
assert!(is_valid_hostname("example.com"));
assert!(is_valid_hostname("sub.example.com"));
assert!(is_valid_hostname("test-host.example.com"));
assert!(is_valid_hostname("localhost"));
// Invalid hostnames
assert!(!is_valid_hostname("192.168.1.1")); // IPv4 address
assert!(!is_valid_hostname("example.localhost")); // Reserved TLD
assert!(!is_valid_hostname("example..com")); // Double dot
assert!(!is_valid_hostname("-example.com")); // Leading hyphen