Skip to main content

ByteArrayViewMut

Trait ByteArrayViewMut 

Source
pub trait ByteArrayViewMut<'transient, 'lifespan: 'transient>: ByteArrayView<'transient, 'lifespan> {
    // Required methods
    fn unit_mut(&mut self) -> &mut Unit;
    fn view_mut(
        &'transient mut self,
    ) -> Result<&'transient mut Bytes, ArrayRetrievalError>;

    // Provided methods
    fn coerce_from_mut<T: Pod>(
        buffer: &'transient mut [u8],
    ) -> Result<&'transient mut [T], ArrayRetrievalError> { ... }
    fn coerce_mut<T: Pod>(
        &'lifespan mut self,
    ) -> Result<&'transient mut [T], ArrayRetrievalError> { ... }
    fn set_data_processing_reference(
        &mut self,
        data_processing_reference: Option<Box<str>>,
    ) { ... }
}
Expand description

A mutable byte array

Required Methods§

Source

fn unit_mut(&mut self) -> &mut Unit

Specify the unit of the data array

Source

fn view_mut( &'transient mut self, ) -> Result<&'transient mut Bytes, ArrayRetrievalError>

Get a mutable view of the bytes backing this data array.

This is in turn used by ByteArrayViewMut::coerce_mut to produce a typed array

Provided Methods§

Source

fn coerce_from_mut<T: Pod>( buffer: &'transient mut [u8], ) -> Result<&'transient mut [T], ArrayRetrievalError>

Reinterpret decoded bytes as a mutable slice in native byte order.

The returned slice borrows the input buffer. T must be Pod so that all bit patterns are valid and writing values cannot introduce padding. Empty buffers return an empty slice.

§Errors

Returns ArrayRetrievalError::DataTypeSizeMismatch if the buffer is not aligned for T or its length is not a multiple of the element size. A nonempty buffer cannot be cast to a zero-sized type.

The returned reference cannot outlive its buffer:

ⓘ
use mzdata_bindata::{ByteArrayViewMut, DataArray};

fn escape_buffer() -> &'static mut [u8] {
    let mut bytes = vec![1u8, 2, 3];
    <DataArray as ByteArrayViewMut<'static, 'static>>::coerce_from_mut::<u8>(
        &mut bytes,
    ).unwrap()
}

Types such as bool cannot represent arbitrary bytes:

ⓘ
use mzdata_bindata::{ByteArrayViewMut, DataArray};

let mut bytes = [0u8];
let _ = <DataArray as ByteArrayViewMut>::coerce_from_mut::<bool>(&mut bytes);
Source

fn coerce_mut<T: Pod>( &'lifespan mut self, ) -> Result<&'transient mut [T], ArrayRetrievalError>

Source

fn set_data_processing_reference( &mut self, data_processing_reference: Option<Box<str>>, )

Set the identifier referencing a DataProcessing

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'transient, 'lifespan: 'transient> ByteArrayViewMut<'transient, 'lifespan> for DataArray