Trait amplify::ByteArray

source ·
pub trait ByteArray<const LEN: usize>: Sized {
    // Required methods
    fn from_byte_array(val: impl Into<[u8; LEN]>) -> Self;
    fn from_slice(slice: impl AsRef<[u8]>) -> Result<Self, FromSliceError>;
    fn from_slice_unsafe(slice: impl AsRef<[u8]>) -> Self;
    fn to_byte_array(&self) -> [u8; LEN];
}
Expand description

Trait which does a blanket implementation for all types wrapping Arrays

Required Methods§

source

fn from_byte_array(val: impl Into<[u8; LEN]>) -> Self

Constructs a wrapper type around a byte array.

source

fn from_slice(slice: impl AsRef<[u8]>) -> Result<Self, FromSliceError>

Constructs a byte array from the slice. Errors if the slice length doesn’t match LEN constant generic.

source

fn from_slice_unsafe(slice: impl AsRef<[u8]>) -> Self

Constructs a byte array from the slice. Expects the slice length doesn’t match LEN constant generic.

§Safety

Panics if the slice length doesn’t match LEN constant generic.

source

fn to_byte_array(&self) -> [u8; LEN]

Returns a byte array representation stored in the wrapped type.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Id, const LEN: usize, const REVERSE_STR: bool> ByteArray<LEN> for Id
where Id: Wrapper<Inner = Array<u8, LEN, REVERSE_STR>>,