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