Struct OnceState

struct OnceState { ... }

State yielded to [Once::call_once_force()]’s closure parameter. The state can be used to query the poison status of the Once.

Implementations

impl OnceState

fn is_poisoned(self: &Self) -> bool

Returns true if the associated Once was poisoned prior to the invocation of the closure passed to [Once::call_once_force()].

Examples

A poisoned [Once]:

use std::sync::Once;
use std::thread;

static INIT: Once = Once::new();

// poison the once
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 std::sync::Once;

static INIT: Once = Once::new();

INIT.call_once_force(|state| {
    assert!(!state.is_poisoned());
});

impl Debug for OnceState

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

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

impl<T> Any for OnceState

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for OnceState

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for OnceState

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for OnceState

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for OnceState

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for OnceState

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for OnceState

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>