Trait binary_layout::FieldSliceAccess

source ·
pub trait FieldSliceAccess<'a>: Field {
    type SliceType: 'a;
    type MutSliceType: 'a;

    // Required methods
    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.

Required Associated Types§

source

type SliceType: 'a

The type of slice returned from calls requesting read access

source

type MutSliceType: 'a

The type of slice returned from calls requesting write access

Required Methods§

source

fn data(storage: &'a [u8]) -> Self::SliceType

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

§Example:
use binary_layout::prelude::*;

binary_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);
}
source

fn data_mut(storage: &'a mut [u8]) -> Self::MutSliceType

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

§Example:
use binary_layout::prelude::*;

binary_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);
}

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, E: Endianness, const N: usize, const OFFSET_: usize> FieldSliceAccess<'a> for PrimitiveField<[u8; N], E, OFFSET_>

Field type [u8; N]: This field represents a fixed size byte array. In this impl, we define accessors for such fields.

§

type SliceType = &'a [u8; N]

§

type MutSliceType = &'a mut [u8; N]

source§

impl<'a, E: Endianness, const OFFSET_: usize> FieldSliceAccess<'a> for PrimitiveField<[u8], E, OFFSET_>

Field type [u8]: This field represents an open ended byte array. In this impl, we define accessors for such fields.

§

type SliceType = &'a [u8]

§

type MutSliceType = &'a mut [u8]