Function state::try_get
[−]
[src]
pub fn try_get<T: Send + Sync + 'static>() -> Option<&'static T>
Attempts to retrieve the global state for type T.
Returns Some if the state has previously been set.
Otherwise returns None.
Example
use std::sync::atomic::{AtomicUsize, Ordering}; struct MyState(AtomicUsize); // State for `T` is initially unset. assert!(state::try_get::<MyState>().is_none()); state::set(MyState(AtomicUsize::new(0))); let my_state = state::try_get::<MyState>().expect("MyState"); assert_eq!(my_state.0.load(Ordering::Relaxed), 0);