Skip to main content

Encoding

Trait Encoding 

Source
pub trait Encoding: Sized {
    type Repr: AsRef<[u8]> + AsMut<[u8]> + Clone + Sized + for<'a> TryFrom<&'a [u8], Error: Error>;

    // Required methods
    fn from_be_bytes(bytes: Self::Repr) -> Self;
    fn from_le_bytes(bytes: Self::Repr) -> Self;
    fn to_be_bytes(&self) -> Self::Repr;
    fn to_le_bytes(&self) -> Self::Repr;
}
Expand description

Encoding support.

Required Associated Types§

Source

type Repr: AsRef<[u8]> + AsMut<[u8]> + Clone + Sized + for<'a> TryFrom<&'a [u8], Error: Error>

Byte array representation.

Required Methods§

Source

fn from_be_bytes(bytes: Self::Repr) -> Self

Decode from big endian bytes.

Source

fn from_le_bytes(bytes: Self::Repr) -> Self

Decode from little endian bytes.

Source

fn to_be_bytes(&self) -> Self::Repr

Encode to big endian bytes.

Source

fn to_le_bytes(&self) -> Self::Repr

Encode to little endian 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.

Implementors§

Source§

impl Encoding for BoxedUint

Available on crate feature alloc only.
Source§

type Repr = Box<[u8]>

Source§

impl Encoding for Limb

Source§

type Repr = [u8; 8]

Source§

impl<const LIMBS: usize> Encoding for Uint<LIMBS>