[][src]Struct ipstuff::MaskedIpv4

pub struct MaskedIpv4 {
    pub ip: Ipv4Addr,
    pub mask: Ipv4Mask,
}

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

impl MaskedIpv4[src]

pub const fn new(ip: Ipv4Addr, mask: Ipv4Mask) -> Self[src]

Constructs a MaskedIpv4 from the provided ip and mask.

pub const fn cidr(ip: Ipv4Addr, mask_len: u8) -> Self[src]

Constructs a MaskedIpv4 from the provided ip and mask length.

Panics

Will panic if provided length > 32

pub fn from_cidr_str(s: &str) -> Option<Self>[src]

Constructs a new MaskedIpv4 from the provided CIDR string.

pub fn from_network_str(s: &str) -> Option<Self>[src]

Constructs a new MaskedIpv4 from the provided IP and subnet mask. There must be exactly one space between the IP and mask.

pub fn to_cidr_string(&self) -> String[src]

Returns a String with the IP and mask in CIDR format. Shortcut for format!("{:#}", self)

pub fn to_network_string(&self) -> String[src]

Returns a String with the IP and mask in dotted decimal format. Shortcut for format!("{}", self)

pub fn network_address(&self) -> Ipv4Addr[src]

Returns the network adderss by setting all host bits to 0.

pub fn network(&self) -> MaskedIpv4[src]

Constructs a new MaskedIpv4 using the network address and mask of this MaskedIpv4.

pub fn is_network_address(&self) -> bool[src]

Returns true if all host bits in the IP are 0. Always returns false if the mask length is 31 or 32.

pub fn broadcast_address(&self) -> Ipv4Addr[src]

Returns the broadcast address by setting all host bits to 1.

pub fn is_broadcast_address(&self) -> bool[src]

Returns true if all host bits in the IP are 1. Always returns false if the mask length is 31 or 32.

pub fn network_bits(&self) -> u8[src]

Returns the number of network bits. That is, the length of the mask.

pub fn host_bits(&self) -> u8[src]

Returns the number of host bits. That is, the number of 0 bits in the mask.

pub fn host_count(&self) -> usize[src]

Returns the number of host addresses in the network.

Panics

Will panic if usize is not large enough to hold the host count.

pub fn host_count_u64(&self) -> u64[src]

Returns the number of host addresses in the network as u64. Unlike host_count, this will never panic.

pub fn network_count(&self, len: u8) -> usize[src]

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

pub fn network_count_u64(&self, len: u8) -> u64[src]

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

pub fn contains(&self, ip: Ipv4Addr) -> bool[src]

Returns true if this network contains the provided IP address, even if the provided IP is the network or broadcast address.

Trait Implementations

impl Clone for MaskedIpv4[src]

impl Copy for MaskedIpv4[src]

impl Debug for MaskedIpv4[src]

impl Display for MaskedIpv4[src]

impl Eq for MaskedIpv4[src]

impl FromStr for MaskedIpv4[src]

type Err = InvalidMaskedIpv4

The associated error which can be returned from parsing.

impl Hash for MaskedIpv4[src]

impl PartialEq<MaskedIpv4> for MaskedIpv4[src]

impl StructuralEq for MaskedIpv4[src]

impl StructuralPartialEq for MaskedIpv4[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.