hopr_lib

Trait IntoEndian

Source
pub trait IntoEndian<const N: usize> {
    // Required methods
    fn from_be_bytes<T>(bytes: T) -> Self
       where T: AsRef<[u8]>;
    fn from_le_bytes<T>(bytes: T) -> Self
       where T: AsRef<[u8]>;
    fn to_le_bytes(self) -> [u8; N];
    fn to_be_bytes(self) -> [u8; N];
}
Expand description

Extension trait for fixed size numbers to allow conversion to/from endian representations.

Required Methods§

Source

fn from_be_bytes<T>(bytes: T) -> Self
where T: AsRef<[u8]>,

Create instance from Big Endian bytes. Should panic if size is more than N.

Source

fn from_le_bytes<T>(bytes: T) -> Self
where T: AsRef<[u8]>,

Create instance from Little Endian bytes. Should panic if size is more than N.

Source

fn to_le_bytes(self) -> [u8; N]

Convert instance to Little Endian bytes.

Source

fn to_be_bytes(self) -> [u8; N]

Convert instance to Big Endian bytes.

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 IntoEndian<32> for U256

Source§

fn from_be_bytes<T>(bytes: T) -> U256
where T: AsRef<[u8]>,

Source§

fn from_le_bytes<T>(bytes: T) -> U256
where T: AsRef<[u8]>,

Source§

fn to_le_bytes(self) -> [u8; 32]

Source§

fn to_be_bytes(self) -> [u8; 32]

Implementors§