Struct OnceState

pub struct OnceState { pub(crate) inner: OnceState }

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

Fields

inner: OnceState

Implementations

impl OnceState

fn is_poisoned(&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());
});
fn poison(&self)

Poison the associated Once without explicitly panicking.

Trait Implementations

impl Debug for OnceState

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

Auto Trait Implementations

impl !Freeze for OnceState

impl !RefUnwindSafe for OnceState

impl !Sync for OnceState

impl Send for OnceState

impl Unpin for OnceState

impl UnsafeUnpin for OnceState

impl UnwindSafe for OnceState

Blanket Implementations

impl<T> Any for OnceState where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for OnceState where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for OnceState where T: ?Sized,

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

impl<T> From<T> for OnceState

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for OnceState where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for OnceState

impl<T, U> Into<U> for OnceState where U: From<T>,

fn into(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<U> for OnceState where U: Into<T>,

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

impl<T, U> TryInto<U> for OnceState where U: TryFrom<T>,

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