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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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.

Source§

type SliceType = &'a [u8; N]

Source§

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.

Source§

type SliceType = &'a [u8]

Source§

type MutSliceType = &'a mut [u8]