net_types::ip

Struct 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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> Freeze for AddrSubnet<S, A>
where A: Freeze, S: Freeze,

§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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>,

Source§

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>,

Source§

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.