pub trait Prefix: Sized + Debug {
type R: Unsigned + PrimInt + Zero + CheckedShr;
// Required methods
fn repr(&self) -> Self::R;
fn prefix_len(&self) -> u8;
fn from_repr_len(repr: Self::R, len: u8) -> Self;
// Provided methods
fn mask(&self) -> Self::R { ... }
fn zero() -> Self { ... }
fn longest_common_prefix(&self, other: &Self) -> Self { ... }
fn contains(&self, other: &Self) -> bool { ... }
fn is_bit_set(&self, bit: u8) -> bool { ... }
fn eq(&self, other: &Self) -> bool { ... }
}Expand description
Trait for defining prefixes.
Required Associated Types§
Required Methods§
Sourcefn repr(&self) -> Self::R
fn repr(&self) -> Self::R
Get raw representation of the address, ignoring the prefix length. This function must return the representation with the mask already applied.
Sourcefn prefix_len(&self) -> u8
fn prefix_len(&self) -> u8
Prefix length
Sourcefn from_repr_len(repr: Self::R, len: u8) -> Self
fn from_repr_len(repr: Self::R, len: u8) -> Self
Create a new prefix from the representation and the prefix pength.
Provided Methods§
Sourcefn mask(&self) -> Self::R
fn mask(&self) -> Self::R
mask self.repr() using self.len(). If you can guarantee that repr is already masked,
them simply re-implement this function for your type.
Sourcefn longest_common_prefix(&self, other: &Self) -> Self
fn longest_common_prefix(&self, other: &Self) -> Self
longest common prefix
Sourcefn contains(&self, other: &Self) -> bool
fn contains(&self, other: &Self) -> bool
Check if self contains other in its prefix range. This function also returns True if
self is identical to other.
Sourcefn is_bit_set(&self, bit: u8) -> bool
fn is_bit_set(&self, bit: u8) -> bool
Check if a specific bit is set (counted from the left, where 0 is the first bit from the left).
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.