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>
impl<S: IpAddress, A: Witness<S> + Copy> AddrSubnet<S, A>
Sourcepub fn new(addr: S, prefix: u8) -> Result<AddrSubnet<S, A>, AddrSubnetError>
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.
Sourcepub unsafe fn new_unchecked(addr: S, prefix: u8) -> Self
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
.
Sourcepub fn from_witness(
addr: A,
prefix: u8,
) -> Result<AddrSubnet<S, A>, AddrSubnetError>
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
).
Sourcepub fn addr_subnet(self) -> (A, Subnet<S>)
pub fn addr_subnet(self) -> (A, Subnet<S>)
Gets the address and subnet.
Sourcepub fn to_witness<B: Witness<S> + Copy>(&self) -> AddrSubnet<S, B>where
A: Into<B>,
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.
Sourcepub fn add_witness<B: Witness<A> + Witness<S> + Copy>(
&self,
) -> Option<AddrSubnet<S, B>>
pub fn add_witness<B: Witness<A> + Witness<S> + Copy>( &self, ) -> Option<AddrSubnet<S, B>>
Wraps an additional witness onto this AddrSubnet
.
Sourcepub fn replace_witness<B: Witness<S> + Copy>(&self) -> Option<AddrSubnet<S, B>>
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>
impl<A: Witness<Ipv6Addr> + Copy> AddrSubnet<Ipv6Addr, A>
Sourcepub fn ipv6_unicast_addr(&self) -> UnicastAddr<Ipv6Addr>
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
.
Sourcepub fn to_unicast(&self) -> AddrSubnet<Ipv6Addr, UnicastAddr<Ipv6Addr>>
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>
impl<S: Clone + IpAddress, A: Clone + Witness<S> + Copy> Clone for AddrSubnet<S, A>
Source§fn clone(&self) -> AddrSubnet<S, A>
fn clone(&self) -> AddrSubnet<S, A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<S: IpAddress, A: IpAddressWitness<S> + Copy> From<AddrSubnet<S, A>> for AddrSubnetEither<A::IpAddrWitness>
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>
fn from(addr_sub: AddrSubnet<S, A>) -> AddrSubnetEither<A::IpAddrWitness>
Source§impl<S: PartialEq + IpAddress, A: PartialEq + Witness<S> + Copy> PartialEq for AddrSubnet<S, A>
impl<S: PartialEq + IpAddress, A: PartialEq + Witness<S> + Copy> PartialEq for AddrSubnet<S, A>
impl<S: Copy + IpAddress, A: Copy + Witness<S> + Copy> Copy for AddrSubnet<S, A>
impl<S: Eq + IpAddress, A: Eq + Witness<S> + Copy> Eq for AddrSubnet<S, A>
impl<S: IpAddress, A: Witness<S> + Copy> StructuralPartialEq for AddrSubnet<S, A>
Auto Trait Implementations§
impl<S, A> Freeze for AddrSubnet<S, A>
impl<S, A> RefUnwindSafe for AddrSubnet<S, A>where
A: RefUnwindSafe,
S: RefUnwindSafe,
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>
impl<S, A> UnwindSafe for AddrSubnet<S, A>where
A: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)