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 emulated from two standard u64 types. This is useful for operations on IPv6 address, which are 128 bit unsigned integers at heart.

Emu128 only implements operations that have been useful for building the Ipv6Net type. It's not intended to be a full u128 implementation.

Examples

use ipnet::Emu128;


let i0 = Emu128::min_value();
let i1 = Emu128 { hi: 1, lo: 1 };
let i2 = Emu128::max_value();
let i3 = Emu128 { hi: 1, lo: std::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

Methods

impl emu128
[src]

Trait Implementations

impl Debug for emu128
[src]

Formats the value using the given formatter.

impl Clone for emu128
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for emu128
[src]

impl PartialEq for emu128
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for emu128
[src]

impl PartialOrd for emu128
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

This method returns an Ordering between self and other. Read more

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the maximum of two values. Read more

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the minimum of two values. Read more

impl Shl<u8> for emu128
[src]

The resulting type after applying the << operator

The method for the << operator

impl Shr<u8> for emu128
[src]

The resulting type after applying the >> operator

The method for the >> operator

impl BitAnd for emu128
[src]

The resulting type after applying the & operator

The method for the & operator

impl BitOr for emu128
[src]

The resulting type after applying the | operator

The method for the | operator

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));

Performs the conversion.

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));

Performs the conversion.