Struct atmega32u4_hal::global::Global [−][src]
pub struct Global<T>(_);
A global variable store
Safe abstraction for global variables
Example
static MY_GLOBAL: atmega32u4_hal::Global<u64> = atmega32u4_hal::Global::new(); fn main() { MY_GLOBAL.set(0xC0FFEE); loop { } } interrupt!(INT1, int1_isr); fn int1_isr() { MY_GLOBAL.get(|v| { // Do something }).expect("Interrupt fired before initialisation!"); }
Methods
impl<T> Global<T>
[src]
impl<T> Global<T>
pub const fn new() -> Global<T>
[src]
pub const fn new() -> Global<T>
Create a new global variable
pub fn set(&self, val: T)
[src]
pub fn set(&self, val: T)
Set this global to some value
Used for initialization
pub fn get<R, F: FnOnce(&mut T) -> R>(&self, f: F) -> Result<R, ()>
[src]
pub fn get<R, F: FnOnce(&mut T) -> R>(&self, f: F) -> Result<R, ()>
Get the value of this global
Will execute f
with the value of the global if the global
has been initialized. If it hasn't been, return Err(())
.
While the closure is executed, interrupts are disabled.