Trait BeBytes

Source
pub trait BeBytes: Sized {
    type ByteArray: AsRef<[u8]>;

    // Required methods
    fn to_be_bytes(self) -> Self::ByteArray;
    fn from_be_bytes(bytes: &[u8]) -> Option<Self>;
}
Expand description

A trait for types that can be encoded to and decoded from big-endian bytes.

Required Associated Types§

Required Methods§

Source

fn to_be_bytes(self) -> Self::ByteArray

Source

fn from_be_bytes(bytes: &[u8]) -> Option<Self>

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 BeBytes for u32

Source§

type ByteArray = [u8; 4]

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn from_be_bytes(bytes: &[u8]) -> Option<Self>

Source§

impl BeBytes for u64

Source§

type ByteArray = [u8; 8]

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn from_be_bytes(bytes: &[u8]) -> Option<Self>

Source§

impl BeBytes for u128

Source§

type ByteArray = [u8; 16]

Source§

fn to_be_bytes(self) -> Self::ByteArray

Source§

fn from_be_bytes(bytes: &[u8]) -> Option<Self>

Implementors§