Trait byte_slice_cast::AsSliceOf
[−]
[src]
pub trait AsSliceOf { fn as_slice_of<'a, T: FromByteSlice>(&'a self) -> Result<&'a [T], Error>; fn as_mut_slice_of<'a, T: FromByteSlice>(
&'a mut self
) -> Result<&'a mut [T], Error>; }
Trait for converting from a byte slice to a slice of another fundamental, built-in numeric
type. This trait is usually more convenient to use than FromByteSlice
.
Example
use byte_slice_cast::*; let slice = [1u8, 2u8, 3u8, 4u8, 5u8, 6u8]; let converted_slice = slice.as_slice_of::<u16>().unwrap(); if cfg!(target_endian = "big") { assert_eq!(converted_slice, &[0x0102, 0x0304, 0x0506]); } else { assert_eq!(converted_slice, &[0x0201, 0x0403, 0x0605]); }
Required Methods
fn as_slice_of<'a, T: FromByteSlice>(&'a self) -> Result<&'a [T], Error>
fn as_mut_slice_of<'a, T: FromByteSlice>(
&'a mut self
) -> Result<&'a mut [T], Error>
&'a mut self
) -> Result<&'a mut [T], Error>