Trait binary_layout::FieldWriteExt

source ·
pub trait FieldWriteExt: Field {
    type HighLevelType;

    // Required method
    fn write(storage: &mut [u8], v: Self::HighLevelType);
}
Expand description

This extension trait adds a FieldWriteExt::write method to any type supporting FieldCopyAccess::try_write that has an implementation that cannot throw errors. This is a convenience function so that callers can just call FieldWriteExt::write instead of having to call FieldCopyAccess::try_write and then calling Result::unwrap on the returned value.

Required Associated Types§

source

type HighLevelType

The data type that is returned from read calls and has to be passed in to write calls. This can be different from the primitive type used in the binary blob, since that primitive type can be wrapped (see WrappedField ) into a high level type before being returned from read calls (or vice versa unwrapped when writing).

Required Methods§

source

fn write(storage: &mut [u8], v: Self::HighLevelType)

Write the field to a given data region, assuming the defined layout, using the Field API.

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

binary_layout!(my_layout, LittleEndian, {
  //... other fields ...
  some_integer_field: u16,
  //... other fields ...
});

fn func(storage_data: &mut [u8]) {
  my_layout::some_integer_field::write(storage_data, 10);
}

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F> FieldWriteExt for F
where F: FieldCopyAccess, F::WriteError: IsInfallible,