Trait ByteRepr

Source
pub trait ByteRepr {
    // Required methods
    fn to_le_bytes(&self) -> Vec<u8> ;
    fn to_be_bytes(&self) -> Vec<u8> ;
}
Expand description

A trait to extract little-endian and big-endian byte representations for any type that supports to_le_bytes() and to_be_bytes().

§Examples

use byte_repr::ByteRepr;

let num: u32 = 0x01020304;
assert_eq!(num.to_le_bytes().to_vec(), vec![0x04, 0x03, 0x02, 0x01]);
assert_eq!(num.to_be_bytes().to_vec(), vec![0x01, 0x02, 0x03, 0x04]);

Required Methods§

Source

fn to_le_bytes(&self) -> Vec<u8>

Returns the little-endian byte representation of the value as a Vec<u8>.

Source

fn to_be_bytes(&self) -> Vec<u8>

Returns the big-endian byte representation of the value as a Vec<u8>.

Implementations on Foreign Types§

Source§

impl ByteRepr for i8

Source§

impl ByteRepr for u16

Source§

impl ByteRepr for u32

Implementors§