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 methods
fn from_slice_unsafe(slice: impl AsRef<[u8]>) -> Self { ... }
fn from_slice_checked(slice: impl AsRef<[u8]>) -> Self { ... }
}
Expand description
Trait which does a blanket implementation for all types wrapping Array
s
Required Methods§
Sourcefn from_byte_array(val: impl Into<[u8; LEN]>) -> Self
fn from_byte_array(val: impl Into<[u8; LEN]>) -> Self
Constructs a wrapper type around a byte array.
Sourcefn from_slice(slice: impl AsRef<[u8]>) -> Result<Self, FromSliceError>
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.
Sourcefn to_byte_array(&self) -> [u8; LEN]
fn to_byte_array(&self) -> [u8; LEN]
Returns a byte array representation stored in the wrapped type.
Provided Methods§
Sourcefn from_slice_unsafe(slice: impl AsRef<[u8]>) -> Self
👎Deprecated since 4.9.0: use from_slice_unsafe instead
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.
Sourcefn from_slice_checked(slice: impl AsRef<[u8]>) -> Self
fn from_slice_checked(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.
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.