pub enum IpNet {
V4(Ipv4Net),
V6(Ipv6Net),
}
Expand description
A subnet, either IPv4 or IPv6
Variants§
Implementations§
Source§impl IpNet
impl IpNet
Sourcepub fn new(addr: IpAddr, prefix: u8) -> Result<Self, IpNetPrefixError>
pub fn new(addr: IpAddr, prefix: u8) -> Result<Self, IpNetPrefixError>
Create an IpNet with the given address and prefix width.
Sourcepub const fn new_unchecked(addr: IpAddr, prefix: u8) -> Self
pub const fn new_unchecked(addr: IpAddr, prefix: u8) -> Self
Create an IpNet with the given address and prefix width with no checks for the validity of the prefix length.
Sourcepub fn host_net(addr: IpAddr) -> Self
pub fn host_net(addr: IpAddr) -> Self
Create an IpNet that contains exclusively the given address.
Sourcepub fn prefix(&self) -> IpAddr
pub fn prefix(&self) -> IpAddr
Return the prefix address (the base address with the mask applied).
Sourcepub const fn is_host_net(&self) -> bool
pub const fn is_host_net(&self) -> bool
Return true
iff the subnet contains only the base address i.e. the
size is exactly one address.
Sourcepub fn is_network_address(&self) -> bool
pub fn is_network_address(&self) -> bool
Return true
iff the base address corresponds to the all-zeroes host
ID in the subnet.
Sourcepub const fn is_multicast(&self) -> bool
pub const fn is_multicast(&self) -> bool
Return true
iff this subnet is in a multicast address range.
Sourcepub const fn is_admin_scoped_multicast(&self) -> bool
pub const fn is_admin_scoped_multicast(&self) -> bool
Sourcepub const fn is_unique_local(&self) -> bool
pub const fn is_unique_local(&self) -> bool
Return true
iff this subnet is in a Unique Local Address range.
This is only valid for IPv6 addresses.
Sourcepub const fn is_loopback(&self) -> bool
pub const fn is_loopback(&self) -> bool
Return true
iff this subnet is in a loopback address range.
Sourcepub fn contains(&self, addr: IpAddr) -> bool
pub fn contains(&self, addr: IpAddr) -> bool
Return true
if the provided address is contained in self.
This returns false
if the address and the network are of different IP
families.
Sourcepub fn is_subnet_of(&self, other: &Self) -> bool
pub fn is_subnet_of(&self, other: &Self) -> bool
Returns true
iff this subnet is wholly contained within other
.
This returns false
if the address and the network are of different IP
families.
Sourcepub fn is_supernet_of(&self, other: &Self) -> bool
pub fn is_supernet_of(&self, other: &Self) -> bool
Returns true
iff other
is wholly contained within this subnet.
This returns false
if the address and the network are of different IP
families.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for IpNet
impl<'de> Deserialize<'de> for IpNet
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for IpNet
impl JsonSchema for IpNet
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read more