integer_encoding

Trait FixedInt

Source
pub trait FixedInt: Sized + Copy {
    const REQUIRED_SPACE: usize;

    // Required methods
    fn required_space() -> usize;
    fn encode_fixed(self, dst: &mut [u8]);
    fn decode_fixed(src: &[u8]) -> Self;
    fn encode_fixed_light<'a>(&'a self) -> &'a [u8] ;

    // Provided methods
    fn encode_fixed_vec(self) -> Vec<u8> { ... }
    fn decode_fixed_vec(v: &Vec<u8>) -> Self { ... }
}
Expand description

FixedInt provides encoding/decoding to and from fixed int representations.

The emitted bytestring contains the bytes of the integer in machine endianness.

Required Associated Constants§

Required Methods§

Source

fn required_space() -> usize

Returns how many bytes are required to represent the given type.

Source

fn encode_fixed(self, dst: &mut [u8])

Encode a value into the given slice. dst must be exactly REQUIRED_SPACE bytes.

Source

fn decode_fixed(src: &[u8]) -> Self

Decode a value from the given slice. src must be exactly REQUIRED_SPACE bytes.

Source

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Perform a transmute, i.e. return a “view” into the integer’s memory, which is faster than performing a copy.

Provided Methods§

Source

fn encode_fixed_vec(self) -> Vec<u8>

Helper: Encode the value and return a Vec.

Source

fn decode_fixed_vec(v: &Vec<u8>) -> Self

Helper: Decode the value from the Vec.

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 FixedInt for i8

Source§

const REQUIRED_SPACE: usize = 1usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> i8

Source§

impl FixedInt for i16

Source§

const REQUIRED_SPACE: usize = 2usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> i16

Source§

impl FixedInt for i32

Source§

const REQUIRED_SPACE: usize = 4usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> i32

Source§

impl FixedInt for i64

Source§

const REQUIRED_SPACE: usize = 8usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> i64

Source§

impl FixedInt for isize

Source§

const REQUIRED_SPACE: usize = 8usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> isize

Source§

impl FixedInt for u8

Source§

const REQUIRED_SPACE: usize = 1usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> u8

Source§

impl FixedInt for u16

Source§

const REQUIRED_SPACE: usize = 2usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> u16

Source§

impl FixedInt for u32

Source§

const REQUIRED_SPACE: usize = 4usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> u32

Source§

impl FixedInt for u64

Source§

const REQUIRED_SPACE: usize = 8usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> u64

Source§

impl FixedInt for usize

Source§

const REQUIRED_SPACE: usize = 8usize

Source§

fn required_space() -> usize

Source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Source§

fn encode_fixed(self, dst: &mut [u8])

Source§

fn decode_fixed(src: &[u8]) -> usize

Implementors§