Struct ipnet::Emu128
[−]
[src]
pub struct Emu128 { pub hi: u64, pub lo: u64, }
An emulated 128 bit unsigned integer.
This module provides Emu128
, a 128 bit unsigned integer that is
emulated using two u64
types. This is useful for operations on
IPv6 address, which are 128 bit unsigned integers.
Currently Emu128
only implements those operations that are useful
for the Ipv6Net
type. It is not intended to become a full u128
implementation.
Conversion between Ipv6Addr
and Emu128
is provided by a From
and Into
implementation on Emu128
.
Examples
use std::u64; use ipnet::Emu128; let i0 = Emu128::min_value(); let i1 = Emu128::from([1, 1]); let i2 = Emu128::max_value(); let i3 = Emu128::from([1, u64::MAX]); assert_eq!(i0, Emu128 { hi: 0, lo: 0 }); assert_eq!(i2, Emu128 { hi: std::u64::MAX, lo: std::u64::MAX }); assert_eq!(i0.saturating_sub(i2), Emu128::min_value()); assert_eq!(i2.saturating_add(i2), Emu128::max_value()); assert_eq!(i1.saturating_add(i1), Emu128 { hi: 2, lo: 2 }); assert_eq!(i2.saturating_sub(i1), Emu128 { hi: std::u64::MAX-1, lo: std::u64::MAX-1 }); assert_eq!(i3.saturating_add(i1), Emu128 { hi: 3, lo: 0 }); assert_eq!(i3.saturating_sub(i1), Emu128 { hi: 0, lo: std::u64::MAX-1 }); assert_eq!(i1 << 1, Emu128 { hi: 2, lo: 2 }); assert_eq!(i1 << 63, Emu128 { hi: 1 << 63, lo: 1 << 63 }); assert_eq!(i1 << 127, Emu128 { hi: 1 << 63, lo: 0 }); assert_eq!(i1 >> 1, Emu128 { hi: 0, lo: 1u64 << 63 }); assert_eq!(i1 >> 63, Emu128 { hi: 0, lo: 2 }); assert_eq!(i1 >> 127, Emu128 { hi: 0, lo: 0 }); assert_eq!(i0 | i1, Emu128 { hi: 1, lo: 1 }); assert_eq!(i1 & i1, Emu128 { hi: 1, lo: 1 }); assert_eq!(i1 & i3, Emu128 { hi: 1, lo: 1 }); assert_eq!(i1 | i3, Emu128 { hi: 1, lo: std::u64::MAX });
Fields
hi: u64
lo: u64
Methods
impl Emu128
[src]
fn min_value() -> Emu128
fn max_value() -> Emu128
fn saturating_add(self, other: Emu128) -> Emu128
fn saturating_sub(self, other: Emu128) -> Emu128
fn leading_zeros(self) -> u32
fn trailing_zeros(self) -> u32
Trait Implementations
impl Debug for Emu128
[src]
impl Clone for Emu128
[src]
fn clone(&self) -> Emu128
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for Emu128
[src]
impl PartialEq for Emu128
[src]
fn eq(&self, __arg_0: &Emu128) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Emu128) -> bool
This method tests for !=
.
impl Eq for Emu128
[src]
impl PartialOrd for Emu128
[src]
fn partial_cmp(&self, __arg_0: &Emu128) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Emu128) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Emu128) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Emu128) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Emu128) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Emu128
[src]
fn cmp(&self, __arg_0: &Emu128) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
ord_max_min
)Compares and returns the minimum of two values. Read more
impl Shl<u8> for Emu128
[src]
type Output = Self
The resulting type after applying the <<
operator
fn shl(self, rhs: u8) -> Emu128
The method for the <<
operator
impl Shr<u8> for Emu128
[src]
type Output = Self
The resulting type after applying the >>
operator
fn shr(self, rhs: u8) -> Emu128
The method for the >>
operator
impl BitAnd for Emu128
[src]
type Output = Self
The resulting type after applying the &
operator
fn bitand(self, rhs: Emu128) -> Emu128
The method for the &
operator
impl BitOr for Emu128
[src]
type Output = Self
The resulting type after applying the |
operator
fn bitor(self, rhs: Emu128) -> Emu128
The method for the |
operator
impl From<[u64; 2]> for Emu128
[src]
Convert an a [u64; 2]
slice into an Emu128
.
Examples
use ipnet::Emu128; let u = Emu128::from([123u64, 123u64]); let v: [u64; 2] = u.into(); assert_eq!(v, [123u64, 123u64]);
impl From<Ipv6Addr> for Emu128
[src]
Convert an Ipv6Addr
into an Emu128
.
Examples
use std::net::Ipv6Addr; use std::str::FromStr; use ipnet::Emu128; let a = Ipv6Addr::from_str("fd00::1").unwrap(); let u = Emu128 { hi: 0xfd00_0000_0000_0000, lo: 1 }; let a2: Ipv6Addr = u.into(); assert_eq!(a, a2); assert_eq!(u, a.into()); assert_eq!(u, Emu128::from(a));
impl Into<Ipv6Addr> for Emu128
[src]
Convert an Emu128
into an Ipv6Addr
.
Examples
use std::net::Ipv6Addr; use std::str::FromStr; use ipnet::Emu128; let a = Ipv6Addr::from_str("fd00::1").unwrap(); let u = Emu128 { hi: 0xfd00_0000_0000_0000, lo: 1 }; let a2: Ipv6Addr = u.into(); assert_eq!(a, a2); assert_eq!(u, a.into()); assert_eq!(u, Emu128::from(a));