U16Packer

Trait U16Packer 

Source
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§

Source

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);
Source

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);
Source

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§

Source

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.

Implementations on Foreign Types§

Source§

impl U16Packer for i32

Source§

fn pack_u16(first: u16, second: u16) -> Self

Source§

fn first_u16(&self) -> u16

Source§

fn second_u16(&self) -> u16

Source§

impl U16Packer for i64

Source§

fn pack_u16(first: u16, second: u16) -> Self

Source§

fn first_u16(&self) -> u16

Source§

fn second_u16(&self) -> u16

Source§

impl U16Packer for isize

Source§

fn pack_u16(first: u16, second: u16) -> Self

Source§

fn first_u16(&self) -> u16

Source§

fn second_u16(&self) -> u16

Source§

impl U16Packer for u32

Source§

fn pack_u16(first: u16, second: u16) -> Self

Source§

fn first_u16(&self) -> u16

Source§

fn second_u16(&self) -> u16

Source§

impl U16Packer for u64

Source§

fn pack_u16(first: u16, second: u16) -> Self

Source§

fn first_u16(&self) -> u16

Source§

fn second_u16(&self) -> u16

Source§

impl U16Packer for usize

Source§

fn pack_u16(first: u16, second: u16) -> Self

Source§

fn first_u16(&self) -> u16

Source§

fn second_u16(&self) -> u16

Implementors§