Trait ndarray_rand::rand_distr::num_traits::ops::bytes::ToBytes

source ·
pub trait ToBytes {
    type Bytes: NumBytes;

    // Required methods
    fn to_be_bytes(&self) -> Self::Bytes;
    fn to_le_bytes(&self) -> Self::Bytes;

    // Provided method
    fn to_ne_bytes(&self) -> Self::Bytes { ... }
}

Required Associated Types§

Required Methods§

source

fn to_be_bytes(&self) -> Self::Bytes

Return the memory representation of this number as a byte array in big-endian byte order.

§Examples
use num_traits::ToBytes;

let bytes = ToBytes::to_be_bytes(&0x12345678u32);
assert_eq!(bytes, [0x12, 0x34, 0x56, 0x78]);
source

fn to_le_bytes(&self) -> Self::Bytes

Return the memory representation of this number as a byte array in little-endian byte order.

§Examples
use num_traits::ToBytes;

let bytes = ToBytes::to_le_bytes(&0x12345678u32);
assert_eq!(bytes, [0x78, 0x56, 0x34, 0x12]);

Provided Methods§

source

fn to_ne_bytes(&self) -> Self::Bytes

Return the memory representation of this number as a byte array in native byte order.

As the target platform’s native endianness is used, portable code should use to_be_bytes or to_le_bytes, as appropriate, instead.

§Examples
use num_traits::ToBytes;

#[cfg(target_endian = "big")]
let expected = [0x12, 0x34, 0x56, 0x78];

#[cfg(target_endian = "little")]
let expected = [0x78, 0x56, 0x34, 0x12];

let bytes = ToBytes::to_ne_bytes(&0x12345678u32);
assert_eq!(bytes, expected)

Implementations on Foreign Types§

source§

impl ToBytes for f32

§

type Bytes = [u8; 4]

source§

fn to_be_bytes(&self) -> <f32 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <f32 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <f32 as ToBytes>::Bytes

source§

impl ToBytes for f64

§

type Bytes = [u8; 8]

source§

fn to_be_bytes(&self) -> <f64 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <f64 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <f64 as ToBytes>::Bytes

source§

impl ToBytes for i8

§

type Bytes = [u8; 1]

source§

fn to_be_bytes(&self) -> <i8 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <i8 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <i8 as ToBytes>::Bytes

source§

impl ToBytes for i16

§

type Bytes = [u8; 2]

source§

fn to_be_bytes(&self) -> <i16 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <i16 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <i16 as ToBytes>::Bytes

source§

impl ToBytes for i32

§

type Bytes = [u8; 4]

source§

fn to_be_bytes(&self) -> <i32 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <i32 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <i32 as ToBytes>::Bytes

source§

impl ToBytes for i64

§

type Bytes = [u8; 8]

source§

fn to_be_bytes(&self) -> <i64 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <i64 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <i64 as ToBytes>::Bytes

source§

impl ToBytes for i128

§

type Bytes = [u8; 16]

source§

fn to_be_bytes(&self) -> <i128 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <i128 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <i128 as ToBytes>::Bytes

source§

impl ToBytes for isize

source§

impl ToBytes for u8

§

type Bytes = [u8; 1]

source§

fn to_be_bytes(&self) -> <u8 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <u8 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <u8 as ToBytes>::Bytes

source§

impl ToBytes for u16

§

type Bytes = [u8; 2]

source§

fn to_be_bytes(&self) -> <u16 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <u16 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <u16 as ToBytes>::Bytes

source§

impl ToBytes for u32

§

type Bytes = [u8; 4]

source§

fn to_be_bytes(&self) -> <u32 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <u32 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <u32 as ToBytes>::Bytes

source§

impl ToBytes for u64

§

type Bytes = [u8; 8]

source§

fn to_be_bytes(&self) -> <u64 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <u64 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <u64 as ToBytes>::Bytes

source§

impl ToBytes for u128

§

type Bytes = [u8; 16]

source§

fn to_be_bytes(&self) -> <u128 as ToBytes>::Bytes

source§

fn to_le_bytes(&self) -> <u128 as ToBytes>::Bytes

source§

fn to_ne_bytes(&self) -> <u128 as ToBytes>::Bytes

source§

impl ToBytes for usize

Implementors§