Skip to main content

ByteArray

Trait 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 to_byte_array(&self) -> [u8; LEN];

    // Provided method
    fn from_slice_checked(slice: impl AsRef<[u8]>) -> Self { ... }
}
Expand description

Trait for fixed-size byte array types and wrappers around them.

Required Methods§

Source

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

Constructs a value from a byte array.

Source

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

Constructs a byte array value from a slice.

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

Source

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

Returns the fixed-size byte array representation of self.

Provided Methods§

Source

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

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<const LEN: usize> ByteArray<LEN> for [u8; LEN]

Source§

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

Source§

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

Source§

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

Implementors§