Skip to main content

ByteArray

Trait ByteArray 

Source
pub trait ByteArray<const N: usize>:
    Sized
    + Copy
    + Debug
    + Eq
    + Hash {
    // 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<(), Error> { ... }
}
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§

Source

fn from_array(array: [u8; N]) -> Self

Source

fn to_array(&self) -> [u8; N]

Source

fn as_array(&self) -> &[u8; N]

Provided Methods§

Source

fn as_slice(&self) -> &[u8]

Source

fn to_vec(&self) -> Vec<u8>

Source

fn try_from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError>

Source

fn try_from_vec(vec: Vec<u8>) -> Result<Self, TryFromSliceError>

Source

fn from_hex(s: &str) -> Result<Self, DecodeError>

Source

fn to_hex(&self) -> String

Source

fn as_hex_display(&self) -> HexDisplay<'_>

Source

fn fmt_as_hex(&self, f: &mut Formatter<'_>) -> Result<(), Error>

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.

Implementations on Foreign Types§

Source§

impl ByteArray<4> for MrShort

Source§

fn from_array(array: [u8; 4]) -> MrShort

Source§

fn to_array(&self) -> [u8; 4]

Source§

fn as_array(&self) -> &[u8; 4]

Source§

impl ByteArray<16> for MachineId

Source§

fn from_array(array: [u8; 16]) -> MachineId

Source§

fn to_array(&self) -> [u8; 16]

Source§

fn as_array(&self) -> &[u8; 16]

Source§

impl ByteArray<32> for Measurement

Source§

fn from_array(array: [u8; 32]) -> Measurement

Source§

fn to_array(&self) -> [u8; 32]

Source§

fn as_array(&self) -> &[u8; 32]

Source§

impl ByteArray<32> for Hash

Source§

fn from_array(array: [u8; 32]) -> Hash

Source§

fn to_array(&self) -> [u8; 32]

Source§

fn as_array(&self) -> &[u8; 32]

Implementors§