AsFixedSizeBytes

Trait AsFixedSizeBytes 

Source
pub trait AsFixedSizeBytes {
    type Buf: Buffer;

    const SIZE: usize;

    // Required methods
    fn as_fixed_size_bytes(&self, buf: &mut [u8]);
    fn from_fixed_size_bytes(buf: &[u8]) -> Self;

    // Provided method
    fn as_new_fixed_size_bytes(&self) -> Self::Buf { ... }
}
Expand description

Allows fast and space-efficient fixed size data encoding.

This trait can be implemented by using [derive::AsFixedSizeBytes] macro. By default it is implemented for the following types:

  1. All primitive types: i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, f32, f64, bool, [()]
  2. Primitive type generic arrays: [i8; N], [u8; N], [i16; N], [u16; N], [i32; N], [u32; N], [i64: N], [u64; N], [i128; N], [u128; N], [f32; N], [f64; N], [bool; N], [(); N]
  3. Tuples up to 6 elements, where each element implements AsFixedSizeBytes
  4. Option of T, where T: AsFixedSizeBytes
  5. IC native types: candid::Principal, candid::Nat, candid::Int

Required Associated Constants§

Source

const SIZE: usize

Size of self when encoded

Required Associated Types§

Source

type Buf: Buffer

Buffer that is used to encode this value into

Required Methods§

Source

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Encodes itself into a slice of bytes.

§Panics

Will panic if out of bounds.

Source

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Decodes itself from a slice of bytes.

§Panics

Will panic if out of bounds.

Provided Methods§

Source

fn as_new_fixed_size_bytes(&self) -> Self::Buf

Encodes itself into a new Self::Buf of size == Self::SIZE

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

Source§

const SIZE: usize = 1usize

Source§

type Buf = [u8; 1]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for char

Source§

const SIZE: usize = 4usize

Source§

type Buf = [u8; 4]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for f32

Source§

const SIZE: usize = 4usize

Source§

type Buf = [u8; 4]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for f64

Source§

const SIZE: usize = 8usize

Source§

type Buf = [u8; 8]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for i8

Source§

const SIZE: usize = 1usize

Source§

type Buf = [u8; 1]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for i16

Source§

const SIZE: usize = 2usize

Source§

type Buf = [u8; 2]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for i32

Source§

const SIZE: usize = 4usize

Source§

type Buf = [u8; 4]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for i64

Source§

const SIZE: usize = 8usize

Source§

type Buf = [u8; 8]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for i128

Source§

const SIZE: usize = 16usize

Source§

type Buf = [u8; 16]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for isize

Source§

const SIZE: usize = 8usize

Source§

type Buf = [u8; 8]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for u8

Source§

const SIZE: usize = 1usize

Source§

type Buf = [u8; 1]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for u16

Source§

const SIZE: usize = 2usize

Source§

type Buf = [u8; 2]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for u32

Source§

const SIZE: usize = 4usize

Source§

type Buf = [u8; 4]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for u64

Source§

const SIZE: usize = 8usize

Source§

type Buf = [u8; 8]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for u128

Source§

const SIZE: usize = 16usize

Source§

type Buf = [u8; 16]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for ()

Source§

const SIZE: usize = 0usize

Source§

type Buf = [u8; 0]

Source§

fn as_fixed_size_bytes(&self, _: &mut [u8])

Source§

fn from_fixed_size_bytes(_: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for usize

Source§

const SIZE: usize = 8usize

Source§

type Buf = [u8; 8]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for Int

Source§

const SIZE: usize = 32usize

Source§

type Buf = [u8; 32]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for Nat

Source§

const SIZE: usize = 32usize

Source§

type Buf = [u8; 32]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl AsFixedSizeBytes for Principal

Source§

const SIZE: usize = 30usize

Source§

type Buf = [u8; 30]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<A: AsFixedSizeBytes> AsFixedSizeBytes for (A,)

Source§

const SIZE: usize = A::SIZE

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<A: AsFixedSizeBytes, B: AsFixedSizeBytes> AsFixedSizeBytes for (A, B)

Source§

const SIZE: usize

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<A: AsFixedSizeBytes, B: AsFixedSizeBytes, C: AsFixedSizeBytes> AsFixedSizeBytes for (A, B, C)

Source§

const SIZE: usize

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<A: AsFixedSizeBytes, B: AsFixedSizeBytes, C: AsFixedSizeBytes, D: AsFixedSizeBytes> AsFixedSizeBytes for (A, B, C, D)

Source§

const SIZE: usize

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<A: AsFixedSizeBytes, B: AsFixedSizeBytes, C: AsFixedSizeBytes, D: AsFixedSizeBytes, E: AsFixedSizeBytes> AsFixedSizeBytes for (A, B, C, D, E)

Source§

const SIZE: usize

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<A: AsFixedSizeBytes, B: AsFixedSizeBytes, C: AsFixedSizeBytes, D: AsFixedSizeBytes, E: AsFixedSizeBytes, F: AsFixedSizeBytes> AsFixedSizeBytes for (A, B, C, D, E, F)

Source§

const SIZE: usize

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<T: AsFixedSizeBytes> AsFixedSizeBytes for Option<T>

Source§

const SIZE: usize

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [bool; N]

Source§

const SIZE: usize = N

Source§

type Buf = [u8; N]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [char; N]

Source§

const SIZE: usize

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [f32; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [f64; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [i8; N]

Source§

const SIZE: usize = N

Source§

type Buf = [u8; N]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [i16; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [i32; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [i64; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [i128; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [isize; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

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

Source§

const SIZE: usize = N

Source§

type Buf = [u8; N]

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [u16; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [u32; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [u64; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [u128; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [(); N]

Source§

const SIZE: usize = 0usize

Source§

type Buf = [u8; 0]

Source§

fn as_fixed_size_bytes(&self, _: &mut [u8])

Source§

fn from_fixed_size_bytes(_: &[u8]) -> Self

Source§

impl<const N: usize> AsFixedSizeBytes for [usize; N]

Source§

const SIZE: usize = N

Source§

type Buf = Vec<u8>

Source§

fn as_fixed_size_bytes(&self, buf: &mut [u8])

Source§

fn from_fixed_size_bytes(buf: &[u8]) -> Self

Implementors§

Source§

impl<K: StableType + AsFixedSizeBytes + Ord + AsHashableBytes, V: StableType + AsFixedSizeBytes + AsHashTree> AsFixedSizeBytes for SCertifiedBTreeMap<K, V>

Source§

const SIZE: usize = 16usize

Source§

type Buf = <SBTreeMap<K, V> as AsFixedSizeBytes>::Buf

Source§

impl<K: StableType + AsFixedSizeBytes + Ord, V: StableType + AsFixedSizeBytes> AsFixedSizeBytes for SBTreeMap<K, V>

Source§

const SIZE: usize = 16usize

Source§

type Buf = [u8; 16]

Source§

impl<K: StableType + AsFixedSizeBytes + Hash + Eq, V: StableType + AsFixedSizeBytes> AsFixedSizeBytes for SHashMap<K, V>

Source§

const SIZE: usize = 24usize

Source§

type Buf = [u8; 24]

Source§

impl<T: StableType + AsFixedSizeBytes + Ord + AsHashableBytes> AsFixedSizeBytes for SCertifiedBTreeSet<T>

Source§

impl<T: StableType + AsFixedSizeBytes + Ord> AsFixedSizeBytes for SBTreeSet<T>

Source§

const SIZE: usize = 16usize

Source§

type Buf = <SBTreeMap<T, ()> as AsFixedSizeBytes>::Buf

Source§

impl<T: StableType + AsFixedSizeBytes + Hash + Eq> AsFixedSizeBytes for SHashSet<T>

Source§

const SIZE: usize = 24usize

Source§

type Buf = <SHashMap<T, ()> as AsFixedSizeBytes>::Buf

Source§

impl<T: StableType + AsFixedSizeBytes> AsFixedSizeBytes for SLog<T>

Source§

const SIZE: usize = 56usize

Source§

type Buf = [u8; 56]

Source§

impl<T: StableType + AsFixedSizeBytes> AsFixedSizeBytes for SVec<T>

Source§

const SIZE: usize = 24usize

Source§

type Buf = [u8; 24]

Source§

impl<T: AsDynSizeBytes + StableType> AsFixedSizeBytes for SBox<T>

Source§

const SIZE: usize = 8usize

Source§

type Buf = [u8; 8]