Trait binary_layout::FieldReadExt

source ·
pub trait FieldReadExt: Field {
    type HighLevelType;

    // Required method
    fn read(storage: &[u8]) -> Self::HighLevelType;
}
Expand description

This extension trait adds a FieldReadExt::read method to any type supporting FieldCopyAccess::try_read that has an implementation that cannot throw errors. This is a convenience function so that callers can just call FieldReadExt::read instead of having to call FieldCopyAccess::try_read 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 read(storage: &[u8]) -> Self::HighLevelType

Read the field from 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: &[u8]) {
  let read: u16 = my_layout::some_integer_field::read(storage_data);
}

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F> FieldReadExt for F
where F: FieldCopyAccess, F::ReadError: IsInfallible,