Available on crate feature
net only.Expand description
Hostname type for network programming.
This module provides a type-safe abstraction for DNS hostnames, ensuring compliance with RFC 1123 hostname specifications.
§RFC 1123 Hostname Rules
According to RFC 1123 §2.1:
- Total length: 1-253 characters
- Each label (segment separated by dots): 1-63 characters
- Valid characters: letters (a-z, A-Z), digits (0-9), and hyphens (-)
- Labels cannot start or end with a hyphen
- Hostnames are case-insensitive (stored in lowercase internally)
- Only ASCII characters are allowed
§Examples
use bare_types::net::Hostname;
// Create a hostname
let hostname = Hostname::new("example.com")?;
// Check if it's localhost
assert!(!hostname.is_localhost());
// Get the string representation
assert_eq!(hostname.as_str(), "example.com");
// Parse from string
let hostname: Hostname = "www.example.com".parse()?;Structs§
- Hostname
- A DNS hostname.
Enums§
- Hostname
Error - Error type for hostname validation.