[][src]Trait byte_struct::ByteStructImpl

pub trait ByteStructImpl {
    const BYTE_LEN: usize;

    fn write_le_bytes(&self, bytes: &mut [u8]);
fn read_le_bytes(bytes: &[u8]) -> Self;
fn write_be_bytes(&self, bytes: &mut [u8]);
fn read_be_bytes(bytes: &[u8]) -> Self; }

A type that can be packed into or unpacked from raw bytes under given default byte order.

This trait is implemented for most numeric primitive types, except for bool, char, isize and usize. This is also implemented for array types whose element type implements ByteStructImpl and whose size is between 1 and 32 (inclusive).

This trait is also implemented for struct with either #[derive(ByteStructLE)] or #[derive(ByteStructBE)].

Members in this trait, except for BYTE_LEN, are meant to be used by byte_struct internal only. They do not do what one might expect: the byte orders specified in read_*_bytes/write_*_bytes functions are only default byte order. The default byte order is only repected when the type itself does not carry byte order specification (e.g. primitive types). In contrast, since ByteStruct-derived structures always have byte order specification, the default byte order has no effect on them, and the three versions of read / write functions, _le_, _be_ and no-spec from ByteStruct, behave exactly the same.

In some cases, one might want to implement ByteStructImpl for custom types so that they can be members of ByteStruct-derived structures.

Associated Constants

const BYTE_LEN: usize

The length of the byte representation of this type

Loading content...

Required methods

fn write_le_bytes(&self, bytes: &mut [u8])

Packs the object into raw bytes with little-endian as the default byte order

fn read_le_bytes(bytes: &[u8]) -> Self

Unpacks raw bytes into a new object with little-endian as the default byte order

fn write_be_bytes(&self, bytes: &mut [u8])

Packs the object into raw bytes with big-endian as the default byte order

fn read_be_bytes(bytes: &[u8]) -> Self

Unpacks raw bytes into a new object with big-endian as the default byte order

Loading content...

Implementations on Foreign Types

impl ByteStructImpl for u8[src]

impl ByteStructImpl for i8[src]

impl ByteStructImpl for u16[src]

impl ByteStructImpl for i16[src]

impl ByteStructImpl for u32[src]

impl ByteStructImpl for i32[src]

impl ByteStructImpl for u64[src]

impl ByteStructImpl for i64[src]

impl ByteStructImpl for u128[src]

impl ByteStructImpl for i128[src]

impl ByteStructImpl for f32[src]

impl ByteStructImpl for f64[src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 1][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 2][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 3][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 4][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 5][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 6][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 7][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 8][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 9][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 10][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 11][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 12][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 13][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 14][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 15][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 16][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 17][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 18][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 19][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 20][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 21][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 22][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 23][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 24][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 25][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 26][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 27][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 28][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 29][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 30][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 31][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 32][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 100][src]

impl<T: ByteStructImpl> ByteStructImpl for [T; 3000][src]

Loading content...

Implementors

Loading content...