Struct iptrie::Ipv6Prefix56
source · pub struct Ipv6Prefix56 { /* private fields */ }Expand description
An Ipv6 prefix limited to 56 bits and encoded as u64 (EXPERIMENTAL)
In many applications, managed Ipv6 prefixes are never longer than 56 bits. In theses cases, it is possible to save memory space by encoding it in 64 bits with its length encoded in the last byte.
|------------ 56 bits ---------------|--8 bits--|
ip prefix slot length
The resulting prefix is 4 times shorter that the corresponding Ipv6 generic prefix.
Implementations§
source§impl Ipv6Prefix56
impl Ipv6Prefix56
sourcepub unsafe fn from_slot_unchecked(slot: u64) -> Self
pub unsafe fn from_slot_unchecked(slot: u64) -> 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: u64) -> Result<Self, IpPrefixError>
pub fn from_slot(slot: u64) -> 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) -> u64
pub fn into_slot(self) -> u64
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 Ipv6Prefix56
impl Ipv6Prefix56
Trait Implementations§
source§impl Clone for Ipv6Prefix56
impl Clone for Ipv6Prefix56
source§fn clone(&self) -> Ipv6Prefix56
fn clone(&self) -> Ipv6Prefix56
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for Ipv6Prefix56
impl Debug for Ipv6Prefix56
source§impl Default for Ipv6Prefix56
impl Default for Ipv6Prefix56
source§fn default() -> Ipv6Prefix56
fn default() -> Ipv6Prefix56
source§impl Display for Ipv6Prefix56
impl Display for Ipv6Prefix56
source§impl From<Ipv6Prefix56> for Ipv6Net
impl From<Ipv6Prefix56> for Ipv6Net
source§fn from(value: Ipv6Prefix56) -> Self
fn from(value: Ipv6Prefix56) -> Self
source§impl From<Ipv6Prefix56> for Ipv6Prefix
impl From<Ipv6Prefix56> for Ipv6Prefix
source§fn from(value: Ipv6Prefix56) -> Self
fn from(value: Ipv6Prefix56) -> 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 Ipv6Prefix56
impl FromStr for Ipv6Prefix56
source§impl Hash for Ipv6Prefix56
impl Hash for Ipv6Prefix56
source§impl IpPrefix for Ipv6Prefix56
impl IpPrefix for Ipv6Prefix56
source§fn bitslot_trunc(&self) -> Self::Slot
fn bitslot_trunc(&self) -> Self::Slot
source§impl IpPrefixCovering<Ipv6Addr> for Ipv6Prefix56
impl IpPrefixCovering<Ipv6Addr> for Ipv6Prefix56
source§impl IpPrefixCovering<Ipv6Net> for Ipv6Prefix56
impl IpPrefixCovering<Ipv6Net> for Ipv6Prefix56
source§impl IpPrefixCovering<Ipv6Prefix> for Ipv6Prefix56
impl IpPrefixCovering<Ipv6Prefix> for Ipv6Prefix56
source§impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix56
impl IpPrefixCovering<Ipv6Prefix120> for Ipv6Prefix56
source§impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Net
impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Net
source§impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Prefix
impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Prefix
source§impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Prefix120
impl IpPrefixCovering<Ipv6Prefix56> for Ipv6Prefix120
source§impl PartialEq<Ipv6Prefix56> for Ipv6Prefix56
impl PartialEq<Ipv6Prefix56> for Ipv6Prefix56
source§fn eq(&self, other: &Ipv6Prefix56) -> bool
fn eq(&self, other: &Ipv6Prefix56) -> bool
self and other values to be equal, and is used
by ==.