pub enum OnceState {
New,
Poisoned,
InProgress,
Done,
}Expand description
Current state of a Once.
Variants§
New
A closure has not been executed yet.
Poisoned
A closure was executed but panicked.
InProgress
A thread is currently executing a closure.
Done
A closure has completed successfully.
Implementations§
Source§impl OnceState
impl OnceState
Sourcepub const fn is_poisoned(self) -> bool
pub const fn is_poisoned(self) -> bool
Returns true if this is the Poisoned state.
When a state is passed to Once::call_once_force, this indicates that
the Once was poisoned before the closure was invoked.
§Examples
A poisoned Once:
use parking_lot::Once;
use std::thread;
static INIT: Once = Once::new();
let handle = thread::spawn(|| {
INIT.call_once(|| panic!());
});
assert!(handle.join().is_err());
INIT.call_once_force(|state| {
assert!(state.is_poisoned());
});An unpoisoned Once:
use parking_lot::Once;
static INIT: Once = Once::new();
INIT.call_once_force(|state| {
assert!(!state.is_poisoned());
});Sourcepub const fn poisoned(self) -> bool
pub const fn poisoned(self) -> bool
Alias for is_poisoned.
Sourcepub const fn is_completed(self) -> bool
pub const fn is_completed(self) -> bool
Returns true if this is the Done state.
Sourcepub const fn done(self) -> bool
pub const fn done(self) -> bool
Alias for is_completed.
Trait Implementations§
impl Copy for OnceState
impl Eq for OnceState
impl StructuralPartialEq for OnceState
Auto Trait Implementations§
impl Freeze for OnceState
impl RefUnwindSafe for OnceState
impl Send for OnceState
impl Sync for OnceState
impl Unpin for OnceState
impl UnsafeUnpin for OnceState
impl UnwindSafe for OnceState
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