pub struct Host(/* private fields */);Expand description
URI authority host.
Implementations§
Source§impl Host
impl Host
pub const fn validate_str(input: &str) -> bool
pub const fn validate_bytes(input: &[u8]) -> bool
Source§impl Host
impl Host
Sourcepub fn new<T: ?Sized + AsRef<[u8]>>(input: &T) -> Result<&Self, InvalidHost<&T>>
pub fn new<T: ?Sized + AsRef<[u8]>>(input: &T) -> Result<&Self, InvalidHost<&T>>
Creates a new host by parsing the input value.
Sourcepub const fn from_bytes(input: &[u8]) -> Result<&Self, InvalidHost<&[u8]>>
pub const fn from_bytes(input: &[u8]) -> Result<&Self, InvalidHost<&[u8]>>
Creates a new host by parsing the input bytes.
Sourcepub const fn from_str(input: &str) -> Result<&Self, InvalidHost<&str>>
pub const fn from_str(input: &str) -> Result<&Self, InvalidHost<&str>>
Creates a new host by parsing the input string.
Sourcepub const unsafe fn new_unchecked_from_bytes(input: &[u8]) -> &Self
pub const unsafe fn new_unchecked_from_bytes(input: &[u8]) -> &Self
Creates a new host from the input bytes without validation.
§Safety
The input bytes must be a valid host.
Sourcepub const unsafe fn new_unchecked(input: &str) -> &Self
pub const unsafe fn new_unchecked(input: &str) -> &Self
Creates a new host from the input string without validation.
§Safety
The input string must be a valid host.
Source§impl Host
impl Host
Sourcepub fn as_pct_str(&self) -> &PctStr
pub fn as_pct_str(&self) -> &PctStr
Returns the host as a percent-encoded string slice.
Sourcepub fn is_ip_literal(&self) -> bool
pub fn is_ip_literal(&self) -> bool
Returns true if this host is an IP-literal (IPv6 address or
IPvFuture).
IP-literals are enclosed in brackets ([...]) as defined in
RFC 3986.
§Example
use iref::uri::Host;
assert!(Host::new("[::1]").unwrap().is_ip_literal());
assert!(!Host::new("example.org").unwrap().is_ip_literal());Sourcepub fn is_ipv4(&self) -> bool
pub fn is_ipv4(&self) -> bool
Returns true if this host is an IPv4 address.
§Example
use iref::uri::Host;
assert!(Host::new("127.0.0.1").unwrap().is_ipv4());
assert!(!Host::new("[::1]").unwrap().is_ipv4());
assert!(!Host::new("example.org").unwrap().is_ipv4());Sourcepub fn is_ipv6(&self) -> bool
pub fn is_ipv6(&self) -> bool
Returns true if this host is an IPv6 address.
IPv6 addresses are enclosed in brackets ([...]) and do not start
with [v (which denotes IPvFuture).
§Example
use iref::uri::Host;
assert!(Host::new("[::1]").unwrap().is_ipv6());
assert!(Host::new("[2001:db8::1]").unwrap().is_ipv6());
assert!(!Host::new("127.0.0.1").unwrap().is_ipv6());
assert!(!Host::new("example.org").unwrap().is_ipv6());Sourcepub fn to_ipv4(&self) -> Option<u32>
pub fn to_ipv4(&self) -> Option<u32>
Parses this host as an IPv4 address and returns it as a u32.
Returns None if the host is not a valid IPv4 address.
§Example
use iref::uri::Host;
assert_eq!(Host::new("127.0.0.1").unwrap().to_ipv4(), Some(0x7f000001));
assert_eq!(Host::new("0.0.0.0").unwrap().to_ipv4(), Some(0));
assert_eq!(Host::new("[::1]").unwrap().to_ipv4(), None);Sourcepub fn to_ipv6(&self) -> Option<u128>
pub fn to_ipv6(&self) -> Option<u128>
Parses this host as an IPv6 address and returns it as a u128.
Returns None if the host is not an IPv6 address.
§Example
use iref::uri::Host;
assert_eq!(Host::new("[::1]").unwrap().to_ipv6(), Some(1));
assert_eq!(
Host::new("[2001:db8::1]").unwrap().to_ipv6(),
Some(0x20010db8_00000000_00000000_00000001)
);
assert_eq!(Host::new("[::0]").unwrap().to_ipv6(), Some(0));
assert_eq!(Host::new("127.0.0.1").unwrap().to_ipv6(), None);