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. The into() method must be used to convert from an Ipv6Addr to an Emu128 because it is not possible to implement From<Emu128> for Ipv6Addr.

Examples

use std::net::Ipv6Addr;
use ipnet::Emu128;

let i1 = Emu128::from(1); // convert from u32
let i2 = Emu128::from([1, 1]); // convert from [u64; 2]
let slice: [u64; 2] = i2.into(); // convert into [u64; 2]

let a1: Ipv6Addr = "fd00::1".parse().unwrap();
let u1 = Emu128 { hi: 0xfd00_0000_0000_0000, lo: 1 };
let a2: Ipv6Addr = u1.into();
let u2: Emu128 = a1.into();

assert_eq!(a1, a2);
assert_eq!(u1, u2);
assert_eq!(u1, Emu128::from(a1));

Fields

Methods

impl Emu128
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

Trait Implementations

impl Copy for Emu128
[src]

impl Clone for Emu128
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for Emu128
[src]

impl PartialEq for Emu128
[src]

[src]

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

[src]

This method tests for !=.

impl Ord for Emu128
[src]

[src]

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

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl PartialOrd for Emu128
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

impl Hash for Emu128
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for Emu128
[src]

[src]

Formats the value using the given formatter. Read more

impl Default for Emu128
[src]

[src]

Returns the "default value" for a type. Read more

impl Shl<u8> for Emu128
[src]

The resulting type after applying the << operator.

[src]

Performs the << operation.

impl Shr<u8> for Emu128
[src]

The resulting type after applying the >> operator.

[src]

Performs the >> operation.

impl BitAnd for Emu128
[src]

The resulting type after applying the & operator.

[src]

Performs the & operation.

impl BitOr for Emu128
[src]

The resulting type after applying the | operator.

[src]

Performs the | operation.

impl From<u32> for Emu128
[src]

[src]

Performs the conversion.

impl From<[u64; 2]> for Emu128
[src]

[src]

Performs the conversion.

impl From<Emu128> for [u64; 2]
[src]

[src]

Performs the conversion.

impl From<Ipv6Addr> for Emu128
[src]

[src]

Performs the conversion.

impl Into<Ipv6Addr> for Emu128
[src]

[src]

Performs the conversion.

impl Display for Emu128
[src]

[src]

Formats the value using the given formatter. Read more

impl IpAdd<Emu128> for Ipv6Addr
[src]

impl IpSub<Emu128> for Ipv6Addr
[src]

impl IpBitAnd<Emu128> for Ipv6Addr
[src]

[src]

impl IpBitOr<Emu128> for Ipv6Addr
[src]

[src]

Auto Trait Implementations

impl Send for Emu128

impl Sync for Emu128