Struct iptrie::Ipv6Prefix120

source ·
pub struct Ipv6Prefix120 { /* private fields */ }
Expand description

An Ipv6 prefix limited to 120 bits and encoded as u128 (EXPERIMENTAL)

In many applications, managed Ipv6 prefixes are never longer than 120 bits. In theses cases, it is possible to save memory space by encoding it in 128 bits with its length encoded in last byte.

|---------------------- 120 bits -----------------------|--8 bits--|
                     ip prefix slot                         length

The resulting prefix is twice as short as the corresponding Ipv6 generic prefix.

Implementations§

source§

impl Ipv6Prefix120

source

pub unsafe fn from_slot_unchecked(slot: u128) -> Self

Creates a prefix from a well structured slot.

A well-structured slot is structured as follows where length is encoded on the last byte (8 bits) and this length should not exceed the prefix limit Self::MAX_LEN.

|------------ ip prefix slot ------------|-- length --|

Results are unpredictable if the last byte is not a valid length.

A safe version of this function exists as Self::from_slot or also [`Self::try_from_slot] which doesn’t panic.

Example
let prefix = "1:1::/48".parse::<Ipv6Prefix56>().unwrap();
let slot : u64 = prefix.into_slot();
assert_eq!( prefix, unsafe { Ipv6Prefix56::from_slot_unchecked(slot)});

let prefix = "1:1::/48".parse::<Ipv6Prefix120>().unwrap();
let slot : u128 = prefix.into_slot();
assert_eq!( prefix, unsafe { Ipv6Prefix120::from_slot_unchecked(slot)});
source

pub fn from_slot(slot: u128) -> Result<Self, IpPrefixError>

Creates a prefix from a well structured slot.

A well-structured slot is structured as follows where length is encoded on the last byte (8 bits) and this length should not exceed the prefix limit Self::MAX_LEN.

|------------ ip prefix slot ------------|-- length --|

It returns an error if the last byte is not a valid length.

If you are sure that the slot is well-structured, an unchecked (and unsafe) version of this function is provided by Self::from_slot_unchecked.

Example
let prefix = "1:1::/48".parse::<Ipv6Prefix56>().unwrap();
let slot : u64 = prefix.into_slot();
assert_eq!( Ok(prefix), Ipv6Prefix56::from_slot(slot));

let prefix = "1:1::/48".parse::<Ipv6Prefix120>().unwrap();
let slot : u128 = prefix.into_slot();
assert_eq!( Ok(prefix), Ipv6Prefix120::from_slot(slot));
source

pub fn into_slot(self) -> u128

Gets the raw value of the inner slot.

This slot is structured as follows where length is encoded on the last byte (8 bits).

|------------ ip prefix slot ------------|-- length --|

The returned slot could be safely used with Self::from_slot_unchecked.

source§

impl Ipv6Prefix120

source

pub fn new(addr: Ipv6Addr, len: u8) -> Result<Self, IpPrefixError>

Trait Implementations§

source§

impl Clone for Ipv6Prefix120

source§

fn clone(&self) -> Ipv6Prefix120

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ipv6Prefix120

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Ipv6Prefix120

source§

fn default() -> Ipv6Prefix120

Returns the “default value” for a type. Read more
source§

impl Display for Ipv6Prefix120

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Ipv6Prefix120> for Ipv6Net

source§

fn from(value: Ipv6Prefix120) -> Self

Converts to this type from the input type.
source§

impl From<Ipv6Prefix120> for Ipv6Prefix

source§

fn from(value: Ipv6Prefix120) -> Self

Converts to this type from the input type.
source§

impl From<Ipv6Prefix56> for Ipv6Prefix120

source§

fn from(value: Ipv6Prefix56) -> Self

Converts to this type from the input type.
source§

impl FromStr for Ipv6Prefix120

§

type Err = IpPrefixError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Ipv6Prefix120

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl IpPrefix for Ipv6Prefix120

§

type Slot = u128

The slot manipulated inside this prefix
source§

fn root() -> Self

Root prefix has a length of 0
source§

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

The inner slot as is Read more
source§

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

The inner slot with all the masked bits set to 0. Read more
source§

fn len(&self) -> u8

Length of the prefix. Read more
source§

const MAX_LEN: u8 = 120u8

The maximum allowed length for this prefix
§

type Addr = Ipv6Addr

The underlying ip address (usually Ipv4Addr or Ipv6Addr)
source§

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

The address of the network defined by the prefixv Read more
source§

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

Mask of the prefix. Read more
source§

impl IpPrefixCovering<Ipv6Addr> for Ipv6Prefix120

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv6Net> for Ipv6Prefix120

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv6Prefix> for Ipv6Prefix120

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Net

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix56

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Prefix120

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl PartialEq<Ipv6Prefix120> for Ipv6Prefix120

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<Ipv6Net> for Ipv6Prefix120

§

type Error = IpPrefixError

The type returned in the event of a conversion error.
source§

fn try_from(value: Ipv6Net) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Ipv6Prefix> for Ipv6Prefix120

§

type Error = IpPrefixError

The type returned in the event of a conversion error.
source§

fn try_from(value: Ipv6Prefix) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Ipv6Prefix120> for Ipv6Prefix56

§

type Error = IpPrefixError

The type returned in the event of a conversion error.
source§

fn try_from(value: Ipv6Prefix120) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Ipv6Prefix120

source§

impl Eq for Ipv6Prefix120

source§

impl StructuralEq for Ipv6Prefix120

source§

impl StructuralPartialEq for Ipv6Prefix120

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<P> IpPrefixCovering<P> for Pwhere P: IpPrefix,

source§

fn covering(&self, other: &P) -> IpPrefixCoverage

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.