I32Packer

Trait I32Packer 

Source
pub trait I32Packer {
    // Required methods
    fn pack_i32(first: i32, second: i32) -> Self;
    fn first_i32(&self) -> i32;
    fn second_i32(&self) -> i32;

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

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

Required Methods§

Source

fn pack_i32(first: i32, second: i32) -> Self

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

§Example
use num_packer::I32Packer;
let packed = u64::pack_i32(-200, 15);
assert_eq!(packed, ((-200i32 as u32 as u64) << 32) + (15u32 as u64));
Source

fn first_i32(&self) -> i32

Gets the first i32 value from the packed representation.

§Example
use num_packer::I32Packer;
let packed = u64::pack_i32(-200, 15);
assert_eq!(packed.first_i32(), -200);
Source

fn second_i32(&self) -> i32

Gets the second i32 value from the packed representation.

§Example
use num_packer::I32Packer;
let packed = u64::pack_i32(-200, 15);
assert_eq!(packed.second_i32(), 15);

Provided Methods§

Source

fn unpack_i32(&self) -> (i32, i32)

Unpacks the single value back into two i32 values.

§Example
use num_packer::I32Packer;
let packed = u64::pack_i32(-200, 15);
let (first, second) = packed.unpack_i32();
assert_eq!((first, second), (-200, 15));

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 I32Packer for i64

Source§

fn pack_i32(first: i32, second: i32) -> Self

Source§

fn first_i32(&self) -> i32

Source§

fn second_i32(&self) -> i32

Source§

impl I32Packer for isize

Source§

fn pack_i32(first: i32, second: i32) -> Self

Source§

fn first_i32(&self) -> i32

Source§

fn second_i32(&self) -> i32

Source§

impl I32Packer for u64

Source§

fn pack_i32(first: i32, second: i32) -> Self

Source§

fn first_i32(&self) -> i32

Source§

fn second_i32(&self) -> i32

Source§

impl I32Packer for usize

Source§

fn pack_i32(first: i32, second: i32) -> Self

Source§

fn first_i32(&self) -> i32

Source§

fn second_i32(&self) -> i32

Implementors§