3
3
//! by the compiler, and are useful in many low-level systems programming and concurrent contexts.
4
4
//!
5
5
//! 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`.
7
7
//!
8
8
//! These wrappers do not depend on the standard library and never panic.
9
9
@@ -28,22 +28,26 @@ use core::{
28
28
/// Allows creating read-only and write-only `Volatile` values.
29
29
pub mod access;
30
30
31
- /// A wrapper type around a reference to a volatile variable .
31
+ /// Wraps a reference to make accesses to referenced value volatile .
32
32
///
33
33
/// 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.
35
36
///
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.
37
41
///
38
- /// TODO: read/write permissions
42
+ /// The size of this struct is the same as the size of the contained reference.
39
43
#[ derive( Default , Clone ) ]
40
44
#[ repr( transparent) ]
41
45
pub struct Volatile < R , A = ReadWrite > {
42
46
reference : R ,
43
47
access : PhantomData < A > ,
44
48
}
45
49
46
- /// Constructor functions
50
+ /// Constructor functions for creating new values
47
51
///
48
52
/// These functions allow to construct a new `Volatile` instance from a reference type. While
49
53
/// the `new` function creates a `Volatile` instance with unrestricted access, there are also
@@ -164,7 +168,8 @@ where
164
168
///
165
169
/// Returns a copy of the read value. Volatile reads are guaranteed not to be optimized
166
170
/// 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.
168
173
///
169
174
/// ## Examples
170
175
///
@@ -191,7 +196,7 @@ where
191
196
///
192
197
/// Volatile writes are guaranteed to not be optimized away by the compiler, but by
193
198
/// 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 .
195
200
///
196
201
/// ## Example
197
202
///
0 commit comments