Trait byte_slice_cast::FromByteSlice
[−]
[src]
pub unsafe trait FromByteSlice where
Self: Sized, { fn from_byte_slice<'a>(_: &'a [u8]) -> Result<&'a [Self], Error>; fn from_mut_byte_slice<'a>(_: &'a mut [u8]) -> Result<&'a mut [Self], Error>; }
Trait for converting from a byte slice to a slice of another fundamental, built-in numeric
type. Usually using the AsSliceOf
trait is more convenient.
Example
use byte_slice_cast::*; let slice = [1u8, 2u8, 3u8, 4u8, 5u8, 6u8]; let converted_slice = <u16 as FromByteSlice>::from_byte_slice(&slice).unwrap(); if cfg!(target_endian = "big") { assert_eq!(converted_slice, &[0x0102, 0x0304, 0x0506]); } else { assert_eq!(converted_slice, &[0x0201, 0x0403, 0x0605]); }
Required Methods
fn from_byte_slice<'a>(_: &'a [u8]) -> Result<&'a [Self], Error>
Convert from an immutable byte slice to a immutable slice of another fundamental, built-in numeric type
fn from_mut_byte_slice<'a>(_: &'a mut [u8]) -> Result<&'a mut [Self], Error>
Convert from an mutable byte slice to a mutable slice of another fundamental, built-in numeric type