Trait byte_slice_cast::AsByteSlice[][src]

pub trait AsByteSlice<T> {
    fn as_byte_slice(&self) -> &[u8];
}

Trait for converting from an immutable slice of a fundamental, built-in numeric type to an immutable byte slice.

Example

use byte_slice_cast::*;

let slice: [u16; 3] = [0x0102, 0x0304, 0x0506];
let converted_slice = slice.as_byte_slice();

if cfg!(target_endian = "big") {
    assert_eq!(converted_slice, &[1u8, 2u8, 3u8, 4u8, 5u8, 6u8]);
} else {
    assert_eq!(converted_slice, &[2u8, 1u8, 4u8, 3u8, 6u8, 5u8]);
}

Required methods

fn as_byte_slice(&self) -> &[u8][src]

Loading content...

Implementors

impl<T: ToByteSlice, U: AsRef<[T]> + ?Sized> AsByteSlice<T> for U[src]

Loading content...