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:
- All primitive types: i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, f32, f64, bool, [()]
- 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]
- Tuples up to 6 elements, where each element implements AsFixedSizeBytes
- Option of
T, whereT: AsFixedSizeBytes - IC native types: candid::Principal, candid::Nat, candid::Int
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn as_fixed_size_bytes(&self, buf: &mut [u8])
fn as_fixed_size_bytes(&self, buf: &mut [u8])
Sourcefn from_fixed_size_bytes(buf: &[u8]) -> Self
fn from_fixed_size_bytes(buf: &[u8]) -> Self
Provided Methods§
Sourcefn as_new_fixed_size_bytes(&self) -> Self::Buf
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.