Trait SizedCodec

Source
pub trait SizedCodec: Codec {
    const LEN_ENCODED: usize;

    // Provided methods
    fn len_encoded(&self) -> usize { ... }
    fn encode_fixed<const N: usize>(&self) -> [u8; N] { ... }
}
Expand description

Trait for types that have a fixed-length encoding

Required Associated Constants§

Source

const LEN_ENCODED: usize

The encoded length of this value.

Provided Methods§

Source

fn len_encoded(&self) -> usize

Returns the encoded length of this value.

Should not be overridden by implementations.

Source

fn encode_fixed<const N: usize>(&self) -> [u8; N]

Encodes a value to fixed-size bytes.

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 SizedCodec for bool

Source§

const LEN_ENCODED: usize = 1usize

Source§

impl SizedCodec for f32

Source§

const LEN_ENCODED: usize = 4usize

Source§

impl SizedCodec for f64

Source§

const LEN_ENCODED: usize = 8usize

Source§

impl SizedCodec for i8

Source§

const LEN_ENCODED: usize = 1usize

Source§

impl SizedCodec for i16

Source§

const LEN_ENCODED: usize = 2usize

Source§

impl SizedCodec for i32

Source§

const LEN_ENCODED: usize = 4usize

Source§

impl SizedCodec for i64

Source§

const LEN_ENCODED: usize = 8usize

Source§

impl SizedCodec for i128

Source§

const LEN_ENCODED: usize = 16usize

Source§

impl SizedCodec for u8

Source§

const LEN_ENCODED: usize = 1usize

Source§

impl SizedCodec for u16

Source§

const LEN_ENCODED: usize = 2usize

Source§

impl SizedCodec for u32

Source§

const LEN_ENCODED: usize = 4usize

Source§

impl SizedCodec for u64

Source§

const LEN_ENCODED: usize = 8usize

Source§

impl SizedCodec for u128

Source§

const LEN_ENCODED: usize = 16usize

Source§

impl<const N: usize> SizedCodec for [u8; N]

Implementors§