Trait IntoEndian

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§

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.

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.

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

Convert instance to Little Endian bytes.

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§

§

impl IntoEndian<32> for U256

§

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

§

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

§

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

§

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

Implementors§

§

impl<C> IntoEndian<32> for Balance<C>
where C: Currency,