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§
Sourcefn pack_i32(first: i32, second: i32) -> Self
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));Sourcefn first_i32(&self) -> i32
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);Sourcefn second_i32(&self) -> i32
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§
Sourcefn unpack_i32(&self) -> (i32, i32)
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.