Prefix

Trait Prefix 

Source
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§

Source

type R: Unsigned + PrimInt + Zero + CheckedShr

How can the prefix be represented. This must be one of u8, u16, u32, u64, or u128.

Required Methods§

Source

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.

Source

fn prefix_len(&self) -> u8

Prefix length

Source

fn from_repr_len(repr: Self::R, len: u8) -> Self

Create a new prefix from the representation and the prefix pength.

Provided Methods§

Source

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.

Source

fn zero() -> Self

Create a prefix that matches everything

Source

fn longest_common_prefix(&self, other: &Self) -> Self

longest common prefix

Source

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.

Source

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).

Source

fn eq(&self, other: &Self) -> bool

Compare two prefixes together

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.

Implementations on Foreign Types§

Source§

impl Prefix for Ipv4Net

Source§

type R = u32

Source§

fn repr(&self) -> u32

Source§

fn prefix_len(&self) -> u8

Source§

fn from_repr_len(repr: u32, len: u8) -> Self

Source§

fn mask(&self) -> u32

Source§

fn zero() -> Self

Source§

fn longest_common_prefix(&self, other: &Self) -> Self

Source§

fn contains(&self, other: &Self) -> bool

Source§

impl Prefix for Ipv6Net

Source§

type R = u128

Source§

fn repr(&self) -> u128

Source§

fn prefix_len(&self) -> u8

Source§

fn from_repr_len(repr: u128, len: u8) -> Self

Source§

fn mask(&self) -> u128

Source§

fn zero() -> Self

Source§

fn longest_common_prefix(&self, other: &Self) -> Self

Source§

fn contains(&self, other: &Self) -> bool

Source§

impl<R> Prefix for (R, u8)

Source§

type R = R

Source§

fn repr(&self) -> R

Source§

fn prefix_len(&self) -> u8

Source§

fn from_repr_len(repr: R, len: u8) -> Self

Implementors§