IpPrefix

Trait IpPrefix 

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

    const MAX_LEN: u8;

    // Required methods
    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 Constants§

Source

const MAX_LEN: u8

The maximum allowed length for this 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 Methods§

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.

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 IpPrefix for Ipv4Addr

Source§

const MAX_LEN: u8 = 32u8

Source§

type Slot = u32

Source§

type Addr = Ipv4Addr

Source§

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

Source§

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

Source§

fn len(&self) -> u8

Source§

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

Source§

impl IpPrefix for Ipv6Addr

Source§

const MAX_LEN: u8 = 128u8

Source§

type Slot = u128

Source§

type Addr = Ipv6Addr

Source§

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

Source§

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

Source§

fn len(&self) -> u8

Source§

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

Source§

impl IpPrefix for Ipv4Net

Source§

const MAX_LEN: u8 = 32u8

Source§

type Slot = u32

Source§

type Addr = Ipv4Addr

Source§

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

Source§

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

Source§

fn len(&self) -> u8

Source§

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

Source§

impl IpPrefix for Ipv6Net

Source§

const MAX_LEN: u8 = 128u8

Source§

type Slot = u128

Source§

type Addr = Ipv6Addr

Source§

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

Source§

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

Source§

fn len(&self) -> u8

Source§

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

Implementors§