pub struct Ipv4Inet { /* private fields */ }
Expand description
Inet
type representing an IPv4 host within a network
Derived ordering, i.e. first sort by address, then by network length.
Implementations§
Source§impl Ipv4Inet
impl Ipv4Inet
Sourcepub const fn new(
addr: Ipv4Addr,
len: u8,
) -> Result<Self, NetworkLengthTooLongError>
pub const fn new( addr: Ipv4Addr, len: u8, ) -> Result<Self, NetworkLengthTooLongError>
Create new host within a network from address and prefix length. If the network length exceeds the address length an error is returned.
Sourcepub const fn new_host(addr: Ipv4Addr) -> Self
pub const fn new_host(addr: Ipv4Addr) -> Self
Create a network containing a single address as host and the network (network length = address length).
Sourcepub fn increment(&mut self) -> bool
pub fn increment(&mut self) -> bool
increments host part (without changing the network part); returns true on wrap around
Sourcepub const fn next(self) -> Option<Self>
pub const fn next(self) -> Option<Self>
Returns next address in network or None
if it was the last address in the network
Sourcepub fn decrement(&mut self) -> bool
pub fn decrement(&mut self) -> bool
decrements host part (without changing the network part); returns true on wrap around
Sourcepub const fn previous(self) -> Option<Self>
pub const fn previous(self) -> Option<Self>
Returns previous address in network or None
if it was the first address in the network
Sourcepub const fn overflowing_add(self, step: u128) -> (Self, bool)
pub const fn overflowing_add(self, step: u128) -> (Self, bool)
Find the nth host after the current one in the current network
Returned boolean indicates whether an overflow occured.
Sourcepub const fn overflowing_sub(self, step: u128) -> (Self, bool)
pub const fn overflowing_sub(self, step: u128) -> (Self, bool)
Find the nth host before the current one in the current network
Returned boolean indicates whether an overflow occured.
Sourcepub const fn first_address(&self) -> Ipv4Addr
pub const fn first_address(&self) -> Ipv4Addr
first address in the network as plain address
Sourcepub const fn last_address(&self) -> Ipv4Addr
pub const fn last_address(&self) -> Ipv4Addr
last address in the network as plain address
Sourcepub const fn network_length(&self) -> u8
pub const fn network_length(&self) -> u8
length in bits of the shared prefix of the contained addresses
Sourcepub const fn is_host_address(&self) -> bool
pub const fn is_host_address(&self) -> bool
whether network represents a single host address
Source§impl Ipv4Inet
impl Ipv4Inet
Sourcepub const fn overflowing_add_u32(self, step: u32) -> (Self, bool)
pub const fn overflowing_add_u32(self, step: u32) -> (Self, bool)
Find the nth host after the current one in the current network (32-bit IPv4 variant)
Returned boolean indicates whether an overflow occured.
Sourcepub const fn overflowing_sub_u32(self, step: u32) -> (Self, bool)
pub const fn overflowing_sub_u32(self, step: u32) -> (Self, bool)
Find the nth host before the current one in the current network (32-bit IPv4 variant)
Returned boolean indicates whether an overflow occured.
Trait Implementations§
Source§impl Inet for Ipv4Inet
impl Inet for Ipv4Inet
Source§fn new(addr: Ipv4Addr, len: u8) -> Result<Self, NetworkLengthTooLongError>
fn new(addr: Ipv4Addr, len: u8) -> Result<Self, NetworkLengthTooLongError>
Source§fn new_host(addr: Ipv4Addr) -> Self
fn new_host(addr: Ipv4Addr) -> Self
Source§fn increment(&mut self) -> bool
fn increment(&mut self) -> bool
Source§fn next(self) -> Option<Self>
fn next(self) -> Option<Self>
None
if it was the last address in the networkSource§fn decrement(&mut self) -> bool
fn decrement(&mut self) -> bool
Source§fn previous(self) -> Option<Self>
fn previous(self) -> Option<Self>
None
if it was the first address in the network