[][src]Trait byte_slice_cast::ToByteSlice

pub unsafe trait ToByteSlice where
    Self: Sized
{ fn to_byte_slice<T: AsRef<[Self]> + ?Sized>(slice: &T) -> &[u8]; }

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

Usually using the AsByteSlice trait is more convenient.

Example

use byte_slice_cast::*;

let slice: [u16; 3] = [0x0102, 0x0304, 0x0506];
let converted_slice = ToByteSlice::to_byte_slice(&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 to_byte_slice<T: AsRef<[Self]> + ?Sized>(slice: &T) -> &[u8]

Convert from an immutable slice of a fundamental, built-in numeric type to an immutable byte slice

Loading content...

Implementations on Foreign Types

impl ToByteSlice for u8[src]

impl ToByteSlice for u16[src]

impl ToByteSlice for u32[src]

impl ToByteSlice for u64[src]

impl ToByteSlice for u128[src]

impl ToByteSlice for i8[src]

impl ToByteSlice for i16[src]

impl ToByteSlice for i32[src]

impl ToByteSlice for i64[src]

impl ToByteSlice for i128[src]

impl ToByteSlice for f32[src]

impl ToByteSlice for f64[src]

Loading content...

Implementors

Loading content...