Skip to content

Commit 7dffe2c

Browse files
committed
Improve documentation
1 parent 46a7603 commit 7dffe2c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/access.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
/// Helper trait that is implemented by [`ReadWrite`] and [`ReadOnly`].
12
pub trait Readable {}
3+
4+
/// Helper trait that is implemented by [`ReadWrite`] and [`WriteOnly`].
25
pub trait Writable {}
36

7+
/// Zero-sized marker type for allowing both read and write access.
48
pub struct ReadWrite;
59
impl Readable for ReadWrite {}
610
impl Writable for ReadWrite {}
711

12+
/// Zero-sized marker type for allowing only read access.
813
pub struct ReadOnly;
914

1015
impl Readable for ReadOnly {}
1116

17+
/// Zero-sized marker type for allowing only write access.
1218
pub struct WriteOnly;
1319
impl Writable for WriteOnly {}

src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! by the compiler, and are useful in many low-level systems programming and concurrent contexts.
44
//!
55
//! The wrapper types *do not* enforce any atomicity guarantees; to also get atomicity, consider
6-
//! looking at the `Atomic` wrapper type found in `libcore` or `libstd`.
6+
//! looking at the `Atomic` wrapper types found in `libcore` or `libstd`.
77
//!
88
//! These wrappers do not depend on the standard library and never panic.
99
@@ -28,22 +28,26 @@ use core::{
2828
/// Allows creating read-only and write-only `Volatile` values.
2929
pub mod access;
3030

31-
/// A wrapper type around a reference to a volatile variable.
31+
/// Wraps a reference to make accesses to referenced value volatile.
3232
///
3333
/// Allows volatile reads and writes on the referenced value. The referenced value needs to
34-
/// be `Copy`, as volatile reads and writes take and return copies of the value.
34+
/// be `Copy` for reading and writing, as volatile reads and writes take and return copies
35+
/// of the value.
3536
///
36-
/// The size of this struct is the same as the size of the contained type.
37+
/// Since not all volatile resources (e.g. memory mapped device registers) are both readable
38+
/// and writable, this type supports limiting the allowed access types through an optional second
39+
/// generic parameter `A` that can be one of `ReadWrite`, `ReadOnly`, or `WriteOnly`. It defaults
40+
/// to `ReadWrite`, which allows all operations.
3741
///
38-
/// TODO: read/write permissions
42+
/// The size of this struct is the same as the size of the contained reference.
3943
#[derive(Default, Clone)]
4044
#[repr(transparent)]
4145
pub struct Volatile<R, A = ReadWrite> {
4246
reference: R,
4347
access: PhantomData<A>,
4448
}
4549

46-
/// Constructor functions
50+
/// Constructor functions for creating new values
4751
///
4852
/// These functions allow to construct a new `Volatile` instance from a reference type. While
4953
/// the `new` function creates a `Volatile` instance with unrestricted access, there are also
@@ -164,7 +168,8 @@ where
164168
///
165169
/// Returns a copy of the read value. Volatile reads are guaranteed not to be optimized
166170
/// away by the compiler, but by themselves do not have atomic ordering
167-
/// guarantees. To also get atomicity, consider looking at the `Atomic` wrapper type.
171+
/// guarantees. To also get atomicity, consider looking at the `Atomic` wrapper types of
172+
/// the standard/`core` library.
168173
///
169174
/// ## Examples
170175
///
@@ -191,7 +196,7 @@ where
191196
///
192197
/// Volatile writes are guaranteed to not be optimized away by the compiler, but by
193198
/// themselves do not have atomic ordering guarantees. To also get atomicity, consider
194-
/// looking at the `Atomic` wrapper type.
199+
/// looking at the `Atomic` wrapper types of the standard/`core` library.
195200
///
196201
/// ## Example
197202
///

0 commit comments

Comments
 (0)