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
impl Ipv6Prefix120
sourcepub unsafe fn from_slot_unchecked(slot: u128) -> Self
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)});sourcepub fn from_slot(slot: u128) -> Result<Self, IpPrefixError>
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));sourcepub fn into_slot(self) -> u128
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
impl Ipv6Prefix120
Trait Implementations§
source§impl Clone for Ipv6Prefix120
impl Clone for Ipv6Prefix120
source§fn clone(&self) -> Ipv6Prefix120
fn clone(&self) -> Ipv6Prefix120
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for Ipv6Prefix120
impl Debug for Ipv6Prefix120
source§impl Default for Ipv6Prefix120
impl Default for Ipv6Prefix120
source§fn default() -> Ipv6Prefix120
fn default() -> Ipv6Prefix120
source§impl Display for Ipv6Prefix120
impl Display for Ipv6Prefix120
source§impl From<Ipv6Prefix120> for Ipv6Net
impl From<Ipv6Prefix120> for Ipv6Net
source§fn from(value: Ipv6Prefix120) -> Self
fn from(value: Ipv6Prefix120) -> Self
source§impl From<Ipv6Prefix120> for Ipv6Prefix
impl From<Ipv6Prefix120> for Ipv6Prefix
source§fn from(value: Ipv6Prefix120) -> Self
fn from(value: Ipv6Prefix120) -> Self
source§impl From<Ipv6Prefix56> for Ipv6Prefix120
impl From<Ipv6Prefix56> for Ipv6Prefix120
source§fn from(value: Ipv6Prefix56) -> Self
fn from(value: Ipv6Prefix56) -> Self
source§impl FromStr for Ipv6Prefix120
impl FromStr for Ipv6Prefix120
source§impl Hash for Ipv6Prefix120
impl Hash for Ipv6Prefix120
source§impl IpPrefix for Ipv6Prefix120
impl IpPrefix for Ipv6Prefix120
source§fn bitslot_trunc(&self) -> Self::Slot
fn bitslot_trunc(&self) -> Self::Slot
source§impl IpPrefixCovering<Ipv6Addr> for Ipv6Prefix120
impl IpPrefixCovering<Ipv6Addr> for Ipv6Prefix120
source§impl IpPrefixCovering<Ipv6Net> for Ipv6Prefix120
impl IpPrefixCovering<Ipv6Net> for Ipv6Prefix120
source§impl IpPrefixCovering<Ipv6Prefix> for Ipv6Prefix120
impl IpPrefixCovering<Ipv6Prefix> for Ipv6Prefix120
source§impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Net
impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Net
source§impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix
impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix
source§impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix56
impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix56
source§impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Prefix120
impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Prefix120
source§impl PartialEq<Ipv6Prefix120> for Ipv6Prefix120
impl PartialEq<Ipv6Prefix120> for Ipv6Prefix120
source§fn eq(&self, other: &Ipv6Prefix120) -> bool
fn eq(&self, other: &Ipv6Prefix120) -> bool
self and other values to be equal, and is used
by ==.