expression
Read a value using a volatile access
A volatile read is an externally observable access that the compiler must preserve according to the volatile API contract. It does not imply atomicity or provide inter-thread synchronization. This no_std function derives a pointer from an ordinary live shared reference to u32; no device register, concurrent writer or arbitrary address is involved. A real MMIO read additionally needs a verified hardware access contract. Expected host stdout (not executed): 27 Common mistake: Assuming volatile permits a data race or reading from an arbitrary address.
Formal Syntax & Structure
rust syntaxrust
unsafe { core::ptr::read_volatile(ptr) }Working Example
Example Snippetrust
#![no_std]pub fn sample(value: &u32) -> u32 { // SAFETY: reference supplies a live, aligned, initialized u32; read-only access. unsafe { core::ptr::read_volatile(value as *const u32) }}