Struct net_types::ip::AddrSubnet

source ·
pub struct AddrSubnet<S: IpAddress, A: Witness<S> + Copy = SpecifiedAddr<S>> { /* private fields */ }
Expand description

An address and that address’s subnet.

An AddrSubnet is a pair of an address and a subnet which maintains the invariant that the address is guaranteed to be a unicast address in the subnet. S is the type of address (Ipv4Addr or Ipv6Addr), and A is the type of the address in the subnet, which is always a witness wrapper around S. By default, it is SpecifiedAddr<S>.

Implementations§

source§

impl<S: IpAddress, A: Witness<S> + Copy> AddrSubnet<S, A>

source

pub fn new(addr: S, prefix: u8) -> Result<AddrSubnet<S, A>, AddrSubnetError>

Creates a new AddrSubnet.

new is like from_witness, except that it also converts addr into the appropriate witness type, returning AddrSubnetError::InvalidWitness if the conversion fails.

source

pub unsafe fn new_unchecked(addr: S, prefix: u8) -> Self

Creates a new AddrSubnet without checking for validity.

§Safety

Unlike new, new_unchecked does not validate that prefix is in the proper range, and does not check that addr is a valid value for the witness type A. It is up to the caller to guarantee that prefix is in the proper range, and A::new(addr) is not None.

source

pub fn from_witness( addr: A, prefix: u8 ) -> Result<AddrSubnet<S, A>, AddrSubnetError>

Creates a new AddrSubnet from an existing witness.

from_witness creates a new AddrSubnet with the given address and prefix length. The network address of the subnet is taken to be the first prefix bits of the address. It returns Err if prefix is longer than the number of bits in this type of IP address (32 for IPv4 and 128 for IPv6) or if addr is not a unicast address in the resulting subnet (see IpAddress::is_unicast_in_subnet).

source

pub fn subnet(&self) -> Subnet<S>

Gets the subnet.

source

pub fn addr(&self) -> A

Gets the address.

source

pub fn addr_subnet(self) -> (A, Subnet<S>)

Gets the address and subnet.

source

pub fn to_witness<B: Witness<S> + Copy>(&self) -> AddrSubnet<S, B>
where A: Into<B>,

Constructs a new AddrSubnet of a different witness type.

source

pub fn add_witness<B: Witness<A> + Witness<S> + Copy>( &self ) -> Option<AddrSubnet<S, B>>

Wraps an additional witness onto this AddrSubnet.

source

pub fn replace_witness<B: Witness<S> + Copy>(&self) -> Option<AddrSubnet<S, B>>

Replaces the AddrSubnet witness.

source§

impl<A: Witness<Ipv6Addr> + Copy> AddrSubnet<Ipv6Addr, A>

source

pub fn ipv6_unicast_addr(&self) -> UnicastAddr<Ipv6Addr>

Gets the address as a UnicastAddr witness.

Since one of the invariants on an AddrSubnet is that its contained address is unicast in its subnet, ipv6_unicast_addr can infallibly convert its stored address to a UnicastAddr.

source

pub fn to_unicast(&self) -> AddrSubnet<Ipv6Addr, UnicastAddr<Ipv6Addr>>

Constructs a new AddrSubnet which stores a UnicastAddr witness.

Since one of the invariants on an AddrSubnet is that its contained address is unicast in its subnet, to_unicast can infallibly convert its stored address to a UnicastAddr.

Trait Implementations§

source§

impl<S: Clone + IpAddress, A: Clone + Witness<S> + Copy> Clone for AddrSubnet<S, A>

source§

fn clone(&self) -> AddrSubnet<S, A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S: Debug + IpAddress, A: Debug + Witness<S> + Copy> Debug for AddrSubnet<S, A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S: IpAddress, A: Witness<S> + Copy + Display> Display for AddrSubnet<S, A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<S: IpAddress, A: IpAddressWitness<S> + Copy> From<AddrSubnet<S, A>> for AddrSubnetEither<A::IpAddrWitness>

source§

fn from(addr_sub: AddrSubnet<S, A>) -> AddrSubnetEither<A::IpAddrWitness>

Converts to this type from the input type.
source§

impl<S: Hash + IpAddress, A: Hash + Witness<S> + Copy> Hash for AddrSubnet<S, A>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<S: PartialEq + IpAddress, A: PartialEq + Witness<S> + Copy> PartialEq for AddrSubnet<S, A>

source§

fn eq(&self, other: &AddrSubnet<S, A>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<S: Copy + IpAddress, A: Copy + Witness<S> + Copy> Copy for AddrSubnet<S, A>

source§

impl<S: Eq + IpAddress, A: Eq + Witness<S> + Copy> Eq for AddrSubnet<S, A>

source§

impl<S: IpAddress, A: Witness<S> + Copy> StructuralPartialEq for AddrSubnet<S, A>

Auto Trait Implementations§

§

impl<S, A> RefUnwindSafe for AddrSubnet<S, A>

§

impl<S, A> Send for AddrSubnet<S, A>
where A: Send,

§

impl<S, A> Sync for AddrSubnet<S, A>
where A: Sync,

§

impl<S, A> Unpin for AddrSubnet<S, A>
where A: Unpin, S: Unpin,

§

impl<S, A> UnwindSafe for AddrSubnet<S, A>
where A: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.