Trait NumberBytes

Source
pub trait NumberBytes: Sized {
    const BYTES: usize;

    // Required methods
    fn to_ne_bytes(self) -> Vec<u8> ;
    fn from_ne_bytes(bytes: &[u8]) -> FromBytesResult<Self>;
    fn to_be_bytes(self) -> Vec<u8> ;
    fn from_be_bytes(bytes: &[u8]) -> FromBytesResult<Self>;
    fn to_le_bytes(self) -> Vec<u8> ;
    fn from_le_bytes(bytes: &[u8]) -> FromBytesResult<Self>;
}

Required Associated Constants§

Source

const BYTES: usize

How many bytes a value of this type consists of.

A single byte explicitly refers to 8 bits and the builtin u8 type.

Required Methods§

Source

fn to_ne_bytes(self) -> Vec<u8>

Returns the memory representation of this integer as a byte array in native byte order.

Type-generic wrapper around [to_ne_bytes] for inbuilt number types. See usize::to_ne_bytes.

Size of the output vector shall always be the value of Self::BYTES.

Source

fn from_ne_bytes(bytes: &[u8]) -> FromBytesResult<Self>

Creates a native endian value from its memory representation as a byte array in native endianness.

Type-generic wrapper around [from_ne_bytes] for inbuilt number types. See usize::from_ne_bytes.

Returns FromBytesError if the size of the given byte-slice is incorrect.

Source

fn to_be_bytes(self) -> Vec<u8>

Returns the memory representation of this integer as a byte array in big-endian (network) byte order.

Type-generic wrapper around [to_be_bytes] for inbuilt number types. See usize::to_be_bytes.

Size of the output vector shall always be the value of Self::BYTES.

Source

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

Creates a native endian integer value from its representation as a byte array in big endian.

Type-generic wrapper around [from_be_bytes] for inbuilt number types. See usize::from_be_bytes.

Returns FromBytesError if the size of the given byte-slice is incorrect.

Source

fn to_le_bytes(self) -> Vec<u8>

Returns the memory representation of this integer as a byte array in little-endian byte order.

Type-generic wrapper around [to_le_bytes] for inbuilt number types. See usize::to_le_bytes.

Size of the output vector shall always be the value of Self::BYTES.

Source

fn from_le_bytes(bytes: &[u8]) -> FromBytesResult<Self>

Creates a native endian integer value from its representation as a byte array in little endian.

Type-generic wrapper around [from_le_bytes] for inbuilt number types. See usize::from_le_bytes.

Returns FromBytesError if the size of the given byte-slice is incorrect.

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 NumberBytes for f32

Source§

impl NumberBytes for f64

Source§

impl NumberBytes for i8

Source§

impl NumberBytes for i16

Source§

impl NumberBytes for i32

Source§

impl NumberBytes for i64

Source§

impl NumberBytes for i128

Source§

impl NumberBytes for isize

Source§

impl NumberBytes for u8

Source§

impl NumberBytes for u16

Source§

impl NumberBytes for u32

Source§

impl NumberBytes for u64

Source§

impl NumberBytes for u128

Source§

impl NumberBytes for usize

Implementors§