pub struct PrimitiveField<T: ?Sized, E: Endianness, const OFFSET_: usize> { /* private fields */ }
Expand description
A PrimitiveField is a Field that directly represents a primitive type like u8, i16, … See Field for more info on this API.
§Example:
use binary_layout::prelude::*;
binary_layout!(my_layout, LittleEndian, {
field_one: u16,
another_field: [u8; 16],
something_else: u32,
tail_data: [u8],
});
fn func(storage_data: &mut [u8]) {
// read some data
let format_version_header: u16 = my_layout::field_one::read(storage_data);
// equivalent: let format_version_header = u16::from_le_bytes((&storage_data[0..2]).try_into().unwrap());
// write some data
my_layout::something_else::write(storage_data, 10);
// equivalent: data_slice[18..22].copy_from_slice(&10u32.to_le_bytes());
// access a data region
let tail_data: &[u8] = my_layout::tail_data::data(storage_data);
// equivalent: let tail_data: &[u8] = &data_slice[22..];
// and modify it
my_layout::tail_data::data_mut(storage_data)[..5].copy_from_slice(&[1, 2, 3, 4, 5]);
// equivalent: data_slice[18..22].copy_from_slice(&[1, 2, 3, 4, 5]);
}
Trait Implementations§
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<[u8], E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<[u8], E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const N: usize, const OFFSET_: usize> Field for PrimitiveField<[u8; N], E, OFFSET_>
impl<E: Endianness, const N: usize, const OFFSET_: usize> Field for PrimitiveField<[u8; N], E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<(), E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<(), E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<N: NestedViewInfo, E: Endianness, const OFFSET_: usize> Field for PrimitiveField<N, E, OFFSET_>
impl<N: NestedViewInfo, E: Endianness, const OFFSET_: usize> Field for PrimitiveField<N, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI128, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI16, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI32, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI64, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroI8, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU128, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU16, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU32, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU64, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<NonZeroU8, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<f32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<f32, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<f64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<f64, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i128, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i16, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i32, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i64, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<i8, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u128, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u16, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u32, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u64, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<u8, E, OFFSET_>
Source§const OFFSET: usize = OFFSET_
const OFFSET: usize = OFFSET_
See Field::OFFSET
Source§type Endian = E
type Endian = E
See Field::Endian
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<(), E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<(), E, OFFSET_>
Source§fn try_read(_storage: &[u8]) -> Result<(), Infallible>
fn try_read(_storage: &[u8]) -> Result<(), Infallible>
‘Read’ the ()
-typed 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_zst_field: ()
//... other fields ...
});
fn func(storage_data: &[u8]) {
let read: () = my_layout::some_zst_field::try_read(storage_data).unwrap();
read
}
In reality, this method doesn’t do any work; ()
is a zero-sized type, so there’s no work to
do. This implementation exists solely to make writing derive
macros simpler.
Source§fn try_write(_storage: &mut [u8], _value: ()) -> Result<(), Infallible>
fn try_write(_storage: &mut [u8], _value: ()) -> Result<(), Infallible>
‘Write’ the ()
-typed 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_zst_field: ()
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_zst_field::try_write(storage_data, ()).unwrap();
}
§WARNING
In reality, this method doesn’t do any work; ()
is a zero-sized type, so there’s no work to
do. This implementation exists solely to make writing derive
macros simpler.
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI128, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroI128, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroI128, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroI128
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroI128, NonZeroIsZeroError>{
let read: core::num::NonZeroI128 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroI128) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroI128) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroI128
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroI128::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI16, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroI16, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroI16, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroI16
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroI16, NonZeroIsZeroError>{
let read: core::num::NonZeroI16 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroI16) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroI16) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroI16
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroI16::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI32, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroI32, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroI32, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroI32
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroI32, NonZeroIsZeroError>{
let read: core::num::NonZeroI32 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroI32) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroI32) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroI32
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroI32::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI64, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroI64, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroI64, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroI64
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroI64, NonZeroIsZeroError>{
let read: core::num::NonZeroI64 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroI64) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroI64) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroI64
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroI64::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroI8, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroI8, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroI8, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroI8
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroI8, NonZeroIsZeroError>{
let read: core::num::NonZeroI8 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroI8) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroI8) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroI8
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroI8::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU128, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroU128, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroU128, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroU128
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroU128, NonZeroIsZeroError>{
let read: core::num::NonZeroU128 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroU128) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroU128) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroU128
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroU128::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU16, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroU16, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroU16, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroU16
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroU16, NonZeroIsZeroError>{
let read: core::num::NonZeroU16 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroU16) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroU16) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroU16
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroU16::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU32, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroU32, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroU32, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroU32
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroU32, NonZeroIsZeroError>{
let read: core::num::NonZeroU32 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroU32) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroU32) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroU32
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroU32::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU64, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroU64, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroU64, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroU64
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroU64, NonZeroIsZeroError>{
let read: core::num::NonZeroU64 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroU64) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroU64) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroU64
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroU64::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<NonZeroU8, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<NonZeroU8, NonZeroIsZeroError>
fn try_read(storage: &[u8]) -> Result<NonZeroU8, NonZeroIsZeroError>
Read the integer 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: core::num::NonZeroU8
//... other fields ...
});
fn func(storage_data: &[u8]) -> Result<core::num::NonZeroU8, NonZeroIsZeroError>{
let read: core::num::NonZeroU8 = my_layout::some_integer_field::try_read(storage_data)?;
Ok(read)
}
Source§fn try_write(storage: &mut [u8], value: NonZeroU8) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: NonZeroU8) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: core::num::NonZeroU8
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
let value = core::num::NonZeroU8::new(10).unwrap();
my_layout::some_integer_field::try_write(storage_data, value).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<f32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<f32, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<f32, Infallible>
fn try_read(storage: &[u8]) -> Result<f32, Infallible>
Read the float field from a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_float_field: f32
//... other fields ...
});
fn func(storage_data: &[u8]) -> f32 {
let read: f32 = my_layout::some_float_field::try_read(storage_data).unwrap();
read
}
§WARNING
At it’s core, this method uses f32::from_bits,
which has some weird behavior around signaling and non-signaling NaN
values. Read the
documentation for f32::from_bits which
explains the situation.
Source§fn try_write(storage: &mut [u8], value: f32) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: f32) -> Result<(), Infallible>
Write the float 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_float_field: f32
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_float_field::try_write(storage_data, 10.0).unwrap();
}
§WARNING
At it’s core, this method uses f32::to_bits,
which has some weird behavior around signaling and non-signaling NaN
values. Read the
documentation for f32::to_bits which
explains the situation.
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<f64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<f64, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<f64, Infallible>
fn try_read(storage: &[u8]) -> Result<f64, Infallible>
Read the float field from a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_float_field: f64
//... other fields ...
});
fn func(storage_data: &[u8]) -> f64 {
let read: f64 = my_layout::some_float_field::try_read(storage_data).unwrap();
read
}
§WARNING
At it’s core, this method uses f64::from_bits,
which has some weird behavior around signaling and non-signaling NaN
values. Read the
documentation for f64::from_bits which
explains the situation.
Source§fn try_write(storage: &mut [u8], value: f64) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: f64) -> Result<(), Infallible>
Write the float 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_float_field: f64
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_float_field::try_write(storage_data, 10.0).unwrap();
}
§WARNING
At it’s core, this method uses f64::to_bits,
which has some weird behavior around signaling and non-signaling NaN
values. Read the
documentation for f64::to_bits which
explains the situation.
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i128, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<i128, Infallible>
fn try_read(storage: &[u8]) -> Result<i128, Infallible>
Read the integer 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: i128
//... other fields ...
});
fn func(storage_data: &[u8]) -> i128 {
let read: i128 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: i128) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: i128) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: i128
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i16, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<i16, Infallible>
fn try_read(storage: &[u8]) -> Result<i16, Infallible>
Read the integer 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: i16
//... other fields ...
});
fn func(storage_data: &[u8]) -> i16 {
let read: i16 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: i16) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: i16) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: i16
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i32, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<i32, Infallible>
fn try_read(storage: &[u8]) -> Result<i32, Infallible>
Read the integer 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: i32
//... other fields ...
});
fn func(storage_data: &[u8]) -> i32 {
let read: i32 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: i32) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: i32) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: i32
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i64, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<i64, Infallible>
fn try_read(storage: &[u8]) -> Result<i64, Infallible>
Read the integer 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: i64
//... other fields ...
});
fn func(storage_data: &[u8]) -> i64 {
let read: i64 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: i64) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: i64) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: i64
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<i8, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<i8, Infallible>
fn try_read(storage: &[u8]) -> Result<i8, Infallible>
Read the integer 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: i8
//... other fields ...
});
fn func(storage_data: &[u8]) -> i8 {
let read: i8 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: i8) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: i8) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: i8
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u128, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u128, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<u128, Infallible>
fn try_read(storage: &[u8]) -> Result<u128, Infallible>
Read the integer 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: u128
//... other fields ...
});
fn func(storage_data: &[u8]) -> u128 {
let read: u128 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: u128) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: u128) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: u128
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u16, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u16, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<u16, Infallible>
fn try_read(storage: &[u8]) -> Result<u16, Infallible>
Read the integer 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]) -> u16 {
let read: u16 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: u16) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: u16) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: u16
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u32, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u32, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<u32, Infallible>
fn try_read(storage: &[u8]) -> Result<u32, Infallible>
Read the integer 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: u32
//... other fields ...
});
fn func(storage_data: &[u8]) -> u32 {
let read: u32 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: u32) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: u32) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: u32
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u64, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u64, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<u64, Infallible>
fn try_read(storage: &[u8]) -> Result<u64, Infallible>
Read the integer 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: u64
//... other fields ...
});
fn func(storage_data: &[u8]) -> u64 {
let read: u64 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: u64) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: u64) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: u64
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
Source§impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u8, E, OFFSET_>
impl<E: Endianness, const OFFSET_: usize> FieldCopyAccess for PrimitiveField<u8, E, OFFSET_>
Source§fn try_read(storage: &[u8]) -> Result<u8, Infallible>
fn try_read(storage: &[u8]) -> Result<u8, Infallible>
Read the integer 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: u8
//... other fields ...
});
fn func(storage_data: &[u8]) -> u8 {
let read: u8 = my_layout::some_integer_field::try_read(storage_data).unwrap();
read
}
Source§fn try_write(storage: &mut [u8], value: u8) -> Result<(), Infallible>
fn try_write(storage: &mut [u8], value: u8) -> Result<(), Infallible>
Write the integer field to a given data region, assuming the defined layout, using the Field API.
§Example:
use binary_layout::prelude::*;
use core::convert::Infallible;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_integer_field: u8
//... other fields ...
});
fn func(storage_data: &mut [u8]) {
my_layout::some_integer_field::try_write(storage_data, 10).unwrap();
}
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.
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§fn data_mut(storage: &'a mut [u8]) -> &'a mut [u8] ⓘ
fn data_mut(storage: &'a mut [u8]) -> &'a mut [u8] ⓘ
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);
}
Source§type MutSliceType = &'a mut [u8]
type MutSliceType = &'a mut [u8]
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.
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§fn data(storage: &'a [u8]) -> &'a [u8; N]
fn data(storage: &'a [u8]) -> &'a [u8; N]
Borrow the data in the byte array with read access using the Field API. See also FieldSliceAccess::data.
§Example:
use binary_layout::prelude::*;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_field: [u8; 5],
//... other fields
});
fn func(storage_data: &[u8]) {
let some_field: &[u8; 5] = my_layout::some_field::data(storage_data);
}
Source§fn data_mut(storage: &'a mut [u8]) -> &'a mut [u8; N]
fn data_mut(storage: &'a mut [u8]) -> &'a mut [u8; N]
Borrow the data in the byte array with write access using the Field API. See also FieldSliceAccess::data_mut
§Example:
use binary_layout::prelude::*;
binary_layout!(my_layout, LittleEndian, {
//... other fields ...
some_field: [u8; 5],
//... other fields
});
fn func(storage_data: &mut [u8]) {
let some_field: &mut [u8; 5] = my_layout::some_field::data_mut(storage_data);
}