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§
const REQUIRED_SPACE: usize
Required Methods§
Sourcefn required_space() -> usize
fn required_space() -> usize
Returns how many bytes are required to represent the given type.
Sourcefn encode_fixed(self, dst: &mut [u8])
fn encode_fixed(self, dst: &mut [u8])
Encode a value into the given slice. dst
must be exactly REQUIRED_SPACE
bytes.
Sourcefn decode_fixed(src: &[u8]) -> Self
fn decode_fixed(src: &[u8]) -> Self
Decode a value from the given slice. src
must be exactly REQUIRED_SPACE
bytes.
Sourcefn encode_fixed_light<'a>(&'a self) -> &'a [u8] ⓘ
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§
Sourcefn encode_fixed_vec(self) -> Vec<u8>
fn encode_fixed_vec(self) -> Vec<u8>
Helper: Encode the value and return a Vec.
Sourcefn decode_fixed_vec(v: &Vec<u8>) -> Self
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.