pub trait U16Packer {
// Required methods
fn pack_u16(first: u16, second: u16) -> Self;
fn first_u16(&self) -> u16;
fn second_u16(&self) -> u16;
// Provided method
fn unpack_u16(&self) -> (u16, u16) { ... }
}Expand description
Trait for packing and unpacking two u16 values into a single value.
Required Methods§
Sourcefn pack_u16(first: u16, second: u16) -> Self
fn pack_u16(first: u16, second: u16) -> Self
Packs two u16 values into a single value of the implementing type.
§Example
use num_packer::U16Packer;
let packed = u32::pack_u16(50000, 40000);
assert_eq!(packed, (50000 << 16) + 40000);Sourcefn first_u16(&self) -> u16
fn first_u16(&self) -> u16
Gets the first u16 value from the packed representation.
§Example
use num_packer::U16Packer;
let packed = u32::pack_u16(50000, 40000);
assert_eq!(packed.first_u16(), 50000);Sourcefn second_u16(&self) -> u16
fn second_u16(&self) -> u16
Gets the second u16 value from the packed representation.
§Example
use num_packer::U16Packer;
let packed = u32::pack_u16(50000, 40000);
assert_eq!(packed.second_u16(), 40000);Provided Methods§
Sourcefn unpack_u16(&self) -> (u16, u16)
fn unpack_u16(&self) -> (u16, u16)
Unpacks the single value back into two u16 values.
§Example
use num_packer::U16Packer;
let packed = u32::pack_u16(50000, 40000);
let (first, second) = packed.unpack_u16();
assert_eq!((first, second), (50000, 40000));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.