Trait iptrie::IpPrefix

source ·
pub trait IpPrefix: Debug + Clone + Copy {
    type Slot: BitSlot;
    type Addr: Display + Clone + Copy + Eq + Hash;

    const MAX_LEN: u8;

    // Required methods
    fn root() -> Self;
    fn bitslot(&self) -> Self::Slot;
    fn bitslot_trunc(&self) -> Self::Slot;
    fn len(&self) -> u8;
    fn network(&self) -> Self::Addr;

    // Provided method
    fn bitmask(&self) -> Self::Slot { ... }
}
Expand description

Ip prefix (as bit prefix)

Required Associated Types§

source

type Slot: BitSlot

The slot manipulated inside this prefix

source

type Addr: Display + Clone + Copy + Eq + Hash

The underlying ip address (usually Ipv4Addr or Ipv6Addr)

Required Associated Constants§

source

const MAX_LEN: u8

The maximum allowed length for this prefix

Required Methods§

source

fn root() -> Self

Root prefix has a length of 0

source

fn bitslot(&self) -> Self::Slot

The inner slot as is

Depending of the implementation, there is no warranty that the masked bits (i.e. with position greater than the length) are set to 0.

For a version of a slot with masked bits set to 0, see Self::bitslot_trunc.

source

fn bitslot_trunc(&self) -> Self::Slot

The inner slot with all the masked bits set to 0.

The result always equals self.bitslot() & self.bitmask() but it is usually faster to compute (depending on the prefix structure)

source

fn len(&self) -> u8

Length of the prefix.

This is the number of significant first bits. Others should be considered as 0 (event if not)

source

fn network(&self) -> Self::Addr

The address of the network defined by the prefixv

All the bits greater than the prefix length are set to 0

Provided Methods§

source

fn bitmask(&self) -> Self::Slot

Mask of the prefix.

The n (prefix length) first bits are set to 1 and the last ones are set to 0.

Implementations on Foreign Types§

source§

impl IpPrefix for Ipv6Addr

§

type Slot = u128

source§

fn root() -> Self

source§

fn bitslot(&self) -> Self::Slot

source§

fn bitslot_trunc(&self) -> Self::Slot

source§

fn len(&self) -> u8

source§

const MAX_LEN: u8 = 128u8

§

type Addr = Ipv6Addr

source§

fn network(&self) -> Self::Addr

source§

impl IpPrefix for Ipv6Net

§

type Slot = u128

source§

fn root() -> Self

source§

fn bitslot(&self) -> Self::Slot

source§

fn bitslot_trunc(&self) -> Self::Slot

source§

fn len(&self) -> u8

source§

const MAX_LEN: u8 = 128u8

§

type Addr = Ipv6Addr

source§

fn network(&self) -> Self::Addr

source§

impl IpPrefix for Ipv4Net

§

type Slot = u32

source§

fn root() -> Self

source§

fn bitslot(&self) -> Self::Slot

source§

fn bitslot_trunc(&self) -> Self::Slot

source§

fn len(&self) -> u8

source§

const MAX_LEN: u8 = 32u8

§

type Addr = Ipv4Addr

source§

fn network(&self) -> Self::Addr

source§

impl IpPrefix for Ipv4Addr

§

type Slot = u32

source§

fn root() -> Self

source§

fn bitslot(&self) -> Self::Slot

source§

fn bitslot_trunc(&self) -> Self::Slot

source§

fn len(&self) -> u8

source§

const MAX_LEN: u8 = 32u8

§

type Addr = Ipv4Addr

source§

fn network(&self) -> Self::Addr

Implementors§