safe_mmio/
fields.rs

1// Copyright 2025 The safe-mmio Authors.
2// This project is dual-licensed under Apache 2.0 and MIT terms.
3// See LICENSE-APACHE and LICENSE-MIT for details.
4
5//! Wrapper types for MMIO fields.
6
7use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
8
9/// Wrapper for a field which may safely be read but not written. Reading may cause side-effects,
10/// changing the state of the device in some way.
11#[derive(Clone, Debug, Default, Eq, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq)]
12#[repr(transparent)]
13pub struct ReadOnly<T>(pub T);
14
15/// Wrapper for a field which may safely be read with no side-effects but not written.
16#[derive(Clone, Debug, Default, Eq, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq)]
17#[repr(transparent)]
18pub struct ReadPure<T>(pub T);
19
20/// Wrapper for a field which may safely be written but not read.
21#[derive(Clone, Debug, Default, Eq, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq)]
22#[repr(transparent)]
23pub struct WriteOnly<T>(pub T);
24
25/// Wrapper for a field which may safely be written and read. Reading may cause side-effects,
26/// changing the state of the device in some way.
27#[derive(Clone, Debug, Default, Eq, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq)]
28#[repr(transparent)]
29pub struct ReadWrite<T>(pub T);
30
31/// Wrapper for a field which may safely be written (with side-effects) and read with no
32/// side-effects.
33#[derive(Clone, Debug, Default, Eq, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq)]
34#[repr(transparent)]
35pub struct ReadPureWrite<T>(pub T);