Struct once_nonstatic::Once [−][src]
pub struct Once { /* fields omitted */ }
Like std::sync::Once
, but relaxing the requirement of &'static self
to
&self
on call_once
. Access to inner state is guarded by a spinlock.
use once_nonstatic::Once; let once = Once::INIT; let mut times_called = 0; for _ in 0..100 { once.call_once(|| { times_called += 1; }); } assert_eq!(1, times_called);
Methods
impl Once
[src]
impl Once
pub const INIT: Once
INIT: Once = Once{lock: <SpinLock>::INIT, inner: <UnsafeCell>::new(None),}
A constant initializer.
The inner values of this struct are not public and as such should not be considered stable.
pub fn call_once<F: FnOnce()>(&self, f: F)
[src]
pub fn call_once<F: FnOnce()>(&self, f: F)
Call a function only once.
This behaves exactly like std::sync::Once
with a relaxed requirement
on the lifetime of &self
.