[go: up one dir, main page]

Function state::set [] [src]

pub fn set<T: Send + Sync + 'static>(state: T) -> bool

Sets the global state for type T if it has not been set before.

If the state for T has previously been set, the state is unchanged and false is returned. Returns true if state is successfully set as the state for T.

Example

use std::sync::atomic::AtomicUsize;

struct MyState(AtomicUsize);

assert_eq!(state::set(MyState(AtomicUsize::new(0))), true);
assert_eq!(state::set(MyState(AtomicUsize::new(1))), false);