Trait prefix_trie::Prefix

source ·
pub trait Prefix: Sized {
    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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Prefix for Ipv4Net

§

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 eq(&self, other: &Self) -> bool

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

§

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 eq(&self, other: &Self) -> bool

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)

§

type R = R

source§

fn repr(&self) -> R

source§

fn prefix_len(&self) -> u8

source§

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

source§

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

Implementors§