oncelock 0.1.0-alpha.0

A fast and simple implementation of OnceLock
Documentation
#[cfg(parking_lot_version = "v0_12")]
use ::parking_lot_0_12 as parking_lot;

use parking_lot::{Once as RawOnce, OnceState as RawOnceState};

pub const LEGACY_POISON_BEHAVIOR: bool = false;

pub struct Once {
    raw: RawOnce,
}
impl Once {
    #[inline]
    pub const fn new() -> Once {
        Once {
            raw: RawOnce::new(),
        }
    }

    #[inline]
    pub fn is_completed(&self) -> bool {
        match self.raw.state() {
            RawOnceState::Done => true,
            _ => false,
        }
    }

    #[inline]
    pub fn call_once(&self, func: impl FnOnce()) {
        self.raw.call_once(func);
    }

    #[inline]
    pub fn call_once_force(&self, inner: impl FnOnce()) {
        self.raw.call_once_force(|_| inner());
    }
}