pub enum Cidr {
V4(Cidr),
V6(Cidr),
}Expand description
CIDR representation
Variants§
Implementations§
Source§impl Cidr
impl Cidr
Sourcepub const fn new(addr: IpAddr, prefix: u8) -> Option<Self>
pub const fn new(addr: IpAddr, prefix: u8) -> Option<Self>
Constructs new CIDR verifying that prefix fits provided addrs
Returns None if prefix is greater than address length
Sourcepub const fn new_v4(addr: Ipv4Addr, prefix: u8) -> Option<Self>
pub const fn new_v4(addr: Ipv4Addr, prefix: u8) -> Option<Self>
Constructs new CIDR verifying that prefix fits provided addrs
Returns None if prefix is greater than address length
Sourcepub const fn new_v6(addr: Ipv6Addr, prefix: u8) -> Option<Self>
pub const fn new_v6(addr: Ipv6Addr, prefix: u8) -> Option<Self>
Constructs new CIDR verifying that prefix fits provided addrs
Returns None if prefix is greater than address length
Sourcepub const fn network_addr(&self) -> IpAddr
pub const fn network_addr(&self) -> IpAddr
Computes network address from provided addr and prefix, which is lowest possible address within CIDR block
Sourcepub const fn broadcast_addr(&self) -> IpAddr
pub const fn broadcast_addr(&self) -> IpAddr
Computes network address from provided addr and prefix, which is highest possible address within CIDR block
Sourcepub const fn contains(&self, addr: IpAddr) -> bool
pub const fn contains(&self, addr: IpAddr) -> bool
Checks if a given addr is contained within self
Sourcepub const fn get(&self, idx: u128) -> Option<IpAddr>
pub const fn get(&self, idx: u128) -> Option<IpAddr>
Attempts to fetch address by idx within the block self
Sourcepub const fn get_unchecked(&self, idx: u128) -> IpAddr
pub const fn get_unchecked(&self, idx: u128) -> IpAddr
Returns address corresponding idx without checking size according to the prefix
This is safe in a sense as it is only wrapping math operation, but it should be only used when you know need to iterate over possible addresses by pre-computing size