Trait byte_slice_cast::AsMutByteSlice
source · pub trait AsMutByteSlice<T> {
// Required method
fn as_mut_byte_slice(&mut self) -> Result<&mut [u8], Error>;
}
Expand description
Trait for converting from a mutable slice of a fundamental, built-in numeric type to a mutable
byte slice. This trait is usually more convenient to use than ToMutByteSlice
.
§Example
use byte_slice_cast::*;
let mut slice: [u16; 3] = [0x0102, 0x0304, 0x0506];
let converted_slice = slice.as_mut_byte_slice().unwrap();
if cfg!(target_endian = "big") {
assert_eq!(converted_slice, &mut [1u8, 2u8, 3u8, 4u8, 5u8, 6u8]);
} else {
assert_eq!(converted_slice, &mut [2u8, 1u8, 4u8, 3u8, 6u8, 5u8]);
}