Provides wrapper types
ReadWrite, which wrap any copy-able type and allows for
volatile memory access to wrapped value. Volatile memory accesses are never optimized away by
the compiler, and are useful in many low-level systems programming and concurrent contexts.
The wrapper types do not enforce any atomicity guarantees; to also get atomicity, consider
looking at the
Atomic wrapper type found in
These wrappers do not depend on the standard library and never panic.
Dealing with Volatile Pointers
Frequently, one may have to deal with volatile pointers, eg, writes to specific memory locations. The canonical way to solve this is to cast the pointer to a volatile wrapper directly, eg:
use volatile::Volatile; let mut_ptr = 0xFEE00000 as *mut u32; let volatile_ptr = mut_ptr as *mut Volatile<u32>;
and then perform operations on the pointer as usual in a volatile way. This method works as all of the volatile wrapper types are the same size as their contained values.