pub struct Once { /* private fields */ }
Expand description
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);
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Once
impl !RefUnwindSafe for Once
impl Send for Once
impl Unpin for Once
impl UnwindSafe for Once
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more