use super::super::Field;
use super::PrimitiveField;
pub trait FieldCopyAccess: Field {
type ReadError;
type WriteError;
type HighLevelType;
fn try_read(storage: &[u8]) -> Result<Self::HighLevelType, Self::ReadError>;
fn try_write(storage: &mut [u8], v: Self::HighLevelType) -> Result<(), Self::WriteError>;
}
macro_rules! impl_field_traits {
($type: ty) => {
impl<E: Endianness, const OFFSET_: usize> Field for PrimitiveField<$type, E, OFFSET_> {
type Endian = E;
const OFFSET: usize = OFFSET_;
const SIZE: Option<usize> = Some(core::mem::size_of::<$type>());
}
impl<'a, E: Endianness, const OFFSET_: usize> StorageToFieldView<&'a [u8]>
for PrimitiveField<$type, E, OFFSET_>
{
type View = FieldView<&'a [u8], Self>;
#[inline(always)]
fn view(storage: &'a [u8]) -> Self::View {
Self::View::new(storage)
}
}
impl<'a, E: Endianness, const OFFSET_: usize> StorageToFieldView<&'a mut [u8]>
for PrimitiveField<$type, E, OFFSET_>
{
type View = FieldView<&'a mut [u8], Self>;
#[inline(always)]
fn view(storage: &'a mut [u8]) -> Self::View {
Self::View::new(storage)
}
}
impl<S: AsRef<[u8]>, E: Endianness, const OFFSET_: usize> StorageIntoFieldView<S>
for PrimitiveField<$type, E, OFFSET_>
{
type View = FieldView<S, Self>;
#[inline(always)]
fn into_view(storage: S) -> Self::View {
Self::View::new(storage)
}
}
};
}
mod primitive_float;
mod primitive_int;
mod primitive_nonzero_int;
mod primitive_unit;
mod read_write_ext;
pub use primitive_nonzero_int::NonZeroIsZeroError;
pub use read_write_ext::{FieldReadExt, FieldWriteExt};