pub struct MaskedIpv4 {
pub ip: Ipv4Addr,
pub mask: Ipv4Mask,
}
Expand description
An 8-byte type representing an IPv4 address and subnet mask pair. The IP may be any ip within the represented network, and the mask may be any valid subnet mask.
Fields§
§ip: Ipv4Addr
The IP address
mask: Ipv4Mask
The subnet mask
Implementations§
Source§impl MaskedIpv4
impl MaskedIpv4
Sourcepub const fn new(ip: Ipv4Addr, mask: Ipv4Mask) -> Self
pub const fn new(ip: Ipv4Addr, mask: Ipv4Mask) -> Self
Constructs a MaskedIpv4 from the provided ip and mask.
Sourcepub const fn cidr(ip: Ipv4Addr, mask_len: u8) -> Self
pub const fn cidr(ip: Ipv4Addr, mask_len: u8) -> Self
Constructs a MaskedIpv4 from the provided ip and mask length.
§Panics
Will panic if provided length > 32
Sourcepub fn from_cidr_str(s: &str) -> Option<Self>
pub fn from_cidr_str(s: &str) -> Option<Self>
Constructs a new MaskedIpv4 from the provided CIDR string.
Sourcepub fn from_network_str(s: &str) -> Option<Self>
pub fn from_network_str(s: &str) -> Option<Self>
Constructs a new MaskedIpv4 from the provided IP and subnet mask. There must be exactly one space between the IP and mask.
Sourcepub fn to_cidr_string(&self) -> String
pub fn to_cidr_string(&self) -> String
Returns a String with the IP and mask in CIDR format. Shortcut for format!("{:#}", self)
Sourcepub fn to_network_string(&self) -> String
pub fn to_network_string(&self) -> String
Returns a String with the IP and mask in dotted decimal format. Shortcut for format!("{}", self)
Sourcepub fn network_address(&self) -> Ipv4Addr
pub fn network_address(&self) -> Ipv4Addr
Returns the network adderss by setting all host bits to 0.
Sourcepub fn network(&self) -> MaskedIpv4
pub fn network(&self) -> MaskedIpv4
Constructs a new MaskedIpv4 using the network address and mask of this MaskedIpv4.
Sourcepub fn is_network_address(&self) -> bool
pub fn is_network_address(&self) -> bool
Returns true if all host bits in the IP are 0. Always returns false if the mask length is 31 or 32.
Sourcepub fn broadcast_address(&self) -> Ipv4Addr
pub fn broadcast_address(&self) -> Ipv4Addr
Returns the broadcast address by setting all host bits to 1.
Sourcepub fn is_broadcast_address(&self) -> bool
pub fn is_broadcast_address(&self) -> bool
Returns true if all host bits in the IP are 1. Always returns false if the mask length is 31 or 32.
Sourcepub fn network_bits(&self) -> u8
pub fn network_bits(&self) -> u8
Returns the number of network bits. That is, the length of the mask.
Sourcepub fn host_bits(&self) -> u8
pub fn host_bits(&self) -> u8
Returns the number of host bits. That is, the number of 0 bits in the mask.
Sourcepub fn host_count(&self) -> usize
pub fn host_count(&self) -> usize
Returns the number of host addresses in the network.
§Panics
Will panic if usize is not large enough to hold the host count.
Sourcepub fn host_count_u64(&self) -> u64
pub fn host_count_u64(&self) -> u64
Returns the number of host addresses in the network as u64. Unlike host_count, this will never panic.
Sourcepub fn network_count(&self, len: u8) -> usize
pub fn network_count(&self, len: u8) -> usize
Returns the number of networks of the provided mask length will fit in this network.
§Panics
Will panic if the provided length is > 32, or if the number of networks does not fit in usize
Sourcepub fn network_count_u64(&self, len: u8) -> u64
pub fn network_count_u64(&self, len: u8) -> u64
Returns the number of networks of the provided mask length will fit in this network as u64. Unlike network_count, this will not panic due to overflow. May still panic if the provided length is too long.
§Panics
Will panic if the provided length is > 32
Trait Implementations§
Source§impl Clone for MaskedIpv4
impl Clone for MaskedIpv4
Source§fn clone(&self) -> MaskedIpv4
fn clone(&self) -> MaskedIpv4
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more