Trait binary_layout::prelude::FieldSliceAccess[][src]

pub trait FieldSliceAccess<'a>: Field {
    type SliceType: 'a;
    type MutSliceType: 'a;
    fn data(storage: &'a [u8]) -> Self::SliceType;
fn data_mut(storage: &'a mut [u8]) -> Self::MutSliceType; }
Expand description

This trait is implemented for fields with “slice access”, i.e. fields that are read/write directly without a copy by returning a borrowed slice to the underlying data.

Associated Types

The type of slice returned from calls requesting read access

The type of slice returned from calls requesting write access

Required methods

Borrow the data in the byte array with read access using the Field API.

Example:

use binary_layout::prelude::*;

define_layout!(my_layout, LittleEndian, {
    //... other fields ...
    tail_data: [u8],
});

fn func(storage_data: &[u8]) {
    let tail_data: &[u8] = my_layout::tail_data::data(storage_data);
}

Borrow the data in the byte array with write access using the Field API.

Example:

use binary_layout::prelude::*;
     
define_layout!(my_layout, LittleEndian, {
    //... other fields ...
    tail_data: [u8],
});

fn func(storage_data: &mut [u8]) {
    let tail_data: &mut [u8] = my_layout::tail_data::data_mut(storage_data);
}

Implementors