U32Packer

Trait U32Packer 

Source
pub trait U32Packer {
    // Required methods
    fn pack_u32(first: u32, second: u32) -> Self;
    fn first_u32(&self) -> u32;
    fn second_u32(&self) -> u32;

    // Provided method
    fn unpack_u32(&self) -> (u32, u32) { ... }
}
Expand description

Trait for packing and unpacking two u32 values into a single value.

Required Methods§

Source

fn pack_u32(first: u32, second: u32) -> Self

Packs two u32 values into a single value of the implementing type.

§Example
use num_packer::U32Packer;
let packed = u64::pack_u32(200, 55);
assert_eq!(packed, (200u64 << 32) + 55);
Source

fn first_u32(&self) -> u32

Gets the first u32 value from the packed representation.

§Example
use num_packer::U32Packer;
let packed = u64::pack_u32(200, 55);
assert_eq!(packed.first_u32(), 200);
Source

fn second_u32(&self) -> u32

Gets the second u32 value from the packed representation.

§Example
use num_packer::U32Packer;
let packed = u64::pack_u32(200, 55);
assert_eq!(packed.second_u32(), 55);
`

Provided Methods§

Source

fn unpack_u32(&self) -> (u32, u32)

Unpacks the single value back into two u32 values.

§Example
use num_packer::U32Packer;
let packed = u64::pack_u32(200, 55);
let (first, second) = packed.unpack_u32();
assert_eq!((first, second), (200, 55));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl U32Packer for i64

Source§

fn pack_u32(first: u32, second: u32) -> Self

Source§

fn first_u32(&self) -> u32

Source§

fn second_u32(&self) -> u32

Source§

impl U32Packer for isize

Source§

fn pack_u32(first: u32, second: u32) -> Self

Source§

fn first_u32(&self) -> u32

Source§

fn second_u32(&self) -> u32

Source§

impl U32Packer for u64

Source§

fn pack_u32(first: u32, second: u32) -> Self

Source§

fn first_u32(&self) -> u32

Source§

fn second_u32(&self) -> u32

Source§

impl U32Packer for usize

Source§

fn pack_u32(first: u32, second: u32) -> Self

Source§

fn first_u32(&self) -> u32

Source§

fn second_u32(&self) -> u32

Implementors§