pub trait ByteArray<const N: usize>:
Copy
+ Debug
+ Eq
+ Hash
+ Sized {
// Required methods
fn from_array(array: [u8; N]) -> Self;
fn to_array(&self) -> [u8; N];
fn as_array(&self) -> &[u8; N];
// Provided methods
fn as_slice(&self) -> &[u8] ⓘ { ... }
fn to_vec(&self) -> Vec<u8> ⓘ { ... }
fn try_from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError> { ... }
fn try_from_vec(vec: Vec<u8>) -> Result<Self, TryFromSliceError> { ... }
fn from_hex(s: &str) -> Result<Self, DecodeError> { ... }
fn to_hex(&self) -> String { ... }
fn as_hex_display(&self) -> HexDisplay<'_> { ... }
fn fmt_as_hex(&self, f: &mut Formatter<'_>) -> Result { ... }
}Expand description
A trait for types represented in memory as a byte array. Should NOT be implemented for types that require validation of the byte array contents.
Required Methods§
fn from_array(array: [u8; N]) -> Self
fn to_array(&self) -> [u8; N]
fn as_array(&self) -> &[u8; N]
Provided Methods§
fn as_slice(&self) -> &[u8] ⓘ
fn to_vec(&self) -> Vec<u8> ⓘ
fn try_from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError>
fn try_from_vec(vec: Vec<u8>) -> Result<Self, TryFromSliceError>
fn from_hex(s: &str) -> Result<Self, DecodeError>
fn to_hex(&self) -> String
fn as_hex_display(&self) -> HexDisplay<'_>
fn fmt_as_hex(&self, f: &mut Formatter<'_>) -> Result
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.