pub trait ByteArray: Sized {
    // Required methods
    fn from_canonical_bytes(bytes: &[u8]) -> Result<Self, ByteArrayError>;
    fn as_bytes(&self) -> &[u8] ;

    // Provided methods
    fn to_vec(&self) -> Vec<u8> { ... }
    fn from_vec(v: &Vec<u8>) -> Result<Self, ByteArrayError> { ... }
}
Expand description

Trait the allows converting to/from array[u8]/vec[u8].

Required Methods§

source

fn from_canonical_bytes(bytes: &[u8]) -> Result<Self, ByteArrayError>

Try and convert the given byte array to the implemented type. Any failures (incorrect array length, implementation-specific checks, etc.) return a ByteArrayError with an explanatory note.

source

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

Return the type as a byte array.

Provided Methods§

source

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

Return the type as a byte vector.

source

fn from_vec(v: &Vec<u8>) -> Result<Self, ByteArrayError>

Try and convert the given byte vector to the implemented type.

Errors

Any failures (incorrect string length, etc) return an ByteArrayError with an explanatory note.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ByteArray for Vec<u8>

source§

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

Implementors§