pub unsafe trait ToMutByteSlicewhere
    Self: Sized,{
    // Required method
    fn to_mut_byte_slice<T: AsMut<[Self]> + ?Sized>(
        slice: &mut T
    ) -> 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.

Usually using the AsMutByteSlice trait is more convenient.

Example

use byte_slice_cast::*;

let mut slice: [u16; 3] = [0x0102, 0x0304, 0x0506];
let converted_slice = ToMutByteSlice::to_mut_byte_slice(&mut slice).unwrap();

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§

source

fn to_mut_byte_slice<T: AsMut<[Self]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

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

Implementations on Foreign Types§

source§

impl ToMutByteSlice for i8

source§

fn to_mut_byte_slice<T: AsMut<[i8]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for i64

source§

fn to_mut_byte_slice<T: AsMut<[i64]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for i128

source§

fn to_mut_byte_slice<T: AsMut<[i128]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for u32

source§

fn to_mut_byte_slice<T: AsMut<[u32]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for u16

source§

fn to_mut_byte_slice<T: AsMut<[u16]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for f64

source§

fn to_mut_byte_slice<T: AsMut<[f64]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for u128

source§

fn to_mut_byte_slice<T: AsMut<[u128]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for i16

source§

fn to_mut_byte_slice<T: AsMut<[i16]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for u64

source§

fn to_mut_byte_slice<T: AsMut<[u64]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for i32

source§

fn to_mut_byte_slice<T: AsMut<[i32]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for u8

source§

fn to_mut_byte_slice<T: AsMut<[u8]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

source§

impl ToMutByteSlice for f32

source§

fn to_mut_byte_slice<T: AsMut<[f32]> + ?Sized>( slice: &mut T ) -> Result<&mut [u8], Error>

Implementors§