[][src]Struct volatile::Volatile

#[repr(transparent)]
pub struct Volatile<T: Copy>(_);

A wrapper type around a volatile variable, which allows for volatile reads and writes to the contained value. The stored type needs to be Copy, as volatile reads and writes take and return copies of the value.

The size of this struct is the same as the size of the contained type.

Methods

impl<T: Copy> Volatile<T>
[src]

pub fn new(value: T) -> Volatile<T>
[src]

Construct a new volatile instance wrapping the given value.

use volatile::Volatile;

let value = Volatile::new(0u32);

Panics

This method never panics.

pub fn read(&self) -> T
[src]

Performs a volatile read of the contained value, returning a copy of the read value. Volatile reads are guaranteed not to be optimized away by the compiler, but by themselves do not have atomic ordering guarantees. To also get atomicity, consider looking at the Atomic wrapper type.

use volatile::Volatile;

let value = Volatile::new(42u32);

assert_eq!(value.read(), 42u32);

Panics

This method never panics.

pub fn write(&mut self, value: T)
[src]

Performs a volatile write, setting the contained value to the given value value. Volatile writes are guaranteed to not be optimized away by the compiler, but by themselves do not have atomic ordering guarantees. To also get atomicity, consider looking at the Atomic wrapper type.

use volatile::Volatile;

let mut value = Volatile::new(0u32);

value.write(42u32);

assert_eq!(value.read(), 42u32);

Panics

This method never panics.

pub fn update<F>(&mut self, f: F) where
    F: FnOnce(&mut T), 
[src]

Performs a volatile read of the contained value, passes a mutable reference to it to the function f, and then performs a volatile write of the (potentially updated) value back to the contained value.

use volatile::Volatile;

let mut value = Volatile::new(21u32);

value.update(|val_ref| *val_ref *= 2);

assert_eq!(value.read(), 42u32);

Panics

Ths method never panics.

Trait Implementations

impl<T: Debug + Copy> Debug for Volatile<T>
[src]

impl<T: Copy> Clone for Volatile<T>
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<T> Send for Volatile<T> where
    T: Send

impl<T> Sync for Volatile<T> where
    T: Sync

Blanket Implementations

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> From for T
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]