pub enum NetAddr {
Inet(IpAddr, u16),
Name(Cow<'static, str>, u16),
}Expand description
A network address.
Either an IP address and port number or else a hostname and port number.
Variants§
Implementations§
Source§impl NetAddr
impl NetAddr
pub fn named<S>(name: S, port: u16) -> Self
pub fn with_port(self, p: u16) -> Self
pub fn with_offset(self, o: u16) -> Self
pub fn is_ip(&self) -> bool
Sourcepub fn is_probably_global(&self) -> bool
pub fn is_probably_global(&self) -> bool
Whether this address is plausibly publicly routable. Returns false for IP literals
in non-globally-routable ranges (loopback, unspecified, RFC 1918 private, link-local,
broadcast, documentation, IPv6 multicast) and the literal localhost. Other hostnames
are trusted and return true. Approximates the (still unstable) IpAddr::is_global
using stable predicates; the IPv6 surface is incomplete (fe80::/10 link-local and
fc00::/7 unique-local addresses are treated as global here).
Sourcepub fn validate(&self) -> Result<(), InvalidNetAddr>
pub fn validate(&self) -> Result<(), InvalidNetAddr>
Checks that this address is well-formed.
A hostname is dot-separated labels, each 1 to 63 characters of ASCII letters,
digits, - and _, not beginning or ending with -, and not digits and dots
alone. RFC 952 and RFC 1123 do not allow _, but names using it are in use. An
IP address must be the address it prints as, so an IPv4 address in IPv6 form is
not well-formed; IpAddr::to_canonical converts it.
Neither the port nor the length of the whole name is checked.
Sourcepub fn unbracketed_string(&self) -> String
pub fn unbracketed_string(&self) -> String
The address without brackets around an IPv6 literal.
This is how fmt::Display printed every address before IPv6 literals were
bracketed. The format is retained here for backwards compatibility.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for NetAddr
Available on crate feature serde only.
impl<'de> Deserialize<'de> for NetAddr
serde only.Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl From<SocketAddr> for NetAddr
impl From<SocketAddr> for NetAddr
Source§fn from(a: SocketAddr) -> Self
fn from(a: SocketAddr) -> Self
Source§impl FromStr for NetAddr
Grammar:
impl FromStr for NetAddr
Grammar:
addr = host -- port is 0
| host ":" port
| "[" host "]" -- port is 0
| "[" host "]:" port
host = IP | name
IP = <std::net::IpAddr>
name = <any sequence of characters, possibly empty>
port = <u16>- Input starting with
[has the port after the last]:. With no]:anywhere there is no port, so[a:80is the name[a:80on port 0. - Input not starting with
[has the port after the last:or defaults to 0 if there is no:. hostis an IP ifIpAddrparses it, a name otherwise.- Parsing the port permits a leading
+and leading zeros.