pub trait Witness<A>:
AsRef<A>
+ Sized
+ Sealed {
// Required methods
fn new(addr: A) -> Option<Self>;
unsafe fn new_unchecked(addr: A) -> Self;
fn into_addr(self) -> A;
// Provided methods
fn from_witness<W: Witness<A>>(addr: W) -> Option<Self> { ... }
fn get(&self) -> A
where A: Copy { ... }
fn transpose<T>(self) -> A::Map<Self::Map<T>>
where Self: TransposableWitness<A>,
A: TransposableWitness<T>,
Self::Map<T>: Witness<T>,
A::Map<Self::Map<T>>: Witness<Self::Map<T>> { ... }
}
Expand description
A type which is a witness to some property about an address.
A type which implements Witness<A>
wraps an address of type A
and
guarantees some property about the wrapped address. It is implemented by
SpecifiedAddr
, UnicastAddr
, MulticastAddr
, LinkLocalAddr
,
and NonMappedAddr
.
Required Methods§
Sourcefn new(addr: A) -> Option<Self>
fn new(addr: A) -> Option<Self>
Constructs a new witness type.
new
returns None
if addr
does not satisfy the property guaranteed
by Self
.
Sourceunsafe fn new_unchecked(addr: A) -> Self
unsafe fn new_unchecked(addr: A) -> Self
Constructs a new witness type without checking to see if addr
actually
satisfies the required property.
§Safety
It is up to the caller to make sure that addr
satisfies the required
property in order to avoid breaking the guarantees of this trait.
Sourcefn into_addr(self) -> A
fn into_addr(self) -> A
Consumes this witness and returns the contained A
.
If A: Copy
, prefer get
instead of into_addr
. get
is idiomatic
for wrapper types which which wrap Copy
types (e.g., see
NonZeroUsize::get
or Cell::get
). into_xxx
methods are
idiomatic only when self
must be consumed by value because the wrapped
value is not Copy
(e.g., see Cell::into_inner
).
Provided Methods§
Sourcefn from_witness<W: Witness<A>>(addr: W) -> Option<Self>
fn from_witness<W: Witness<A>>(addr: W) -> Option<Self>
Constructs a new witness type from an existing witness type.
from_witness(witness)
is equivalent to new(witness.into_addr())
.
Sourcefn transpose<T>(self) -> A::Map<Self::Map<T>>where
Self: TransposableWitness<A>,
A: TransposableWitness<T>,
Self::Map<T>: Witness<T>,
A::Map<Self::Map<T>>: Witness<Self::Map<T>>,
fn transpose<T>(self) -> A::Map<Self::Map<T>>where
Self: TransposableWitness<A>,
A: TransposableWitness<T>,
Self::Map<T>: Witness<T>,
A::Map<Self::Map<T>>: Witness<Self::Map<T>>,
Transposes this witness type with another witness type layered inside of
it.
(e.g. UnicastAddr<SpecifiedAddr
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.