oncelock 0.1.0-alpha.0

A fast and simple implementation of OnceLock
Documentation
#[cfg(spin_version = "v0_10")]
use spin_0_10 as spin;
#[cfg(spin_version = "v0_9")]
use spin_0_9 as spin;

pub const LEGACY_POISON_BEHAVIOR: bool = {
    #[cfg(spin_version = "v0_10")]
    {
        false
    }
    #[cfg(not(spin_version = "v0_9"))]
    {
        true
    }
};

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

    #[inline]
    pub fn is_completed(&self) -> bool {
        self.raw.is_completed()
    }

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

    #[inline]
    pub fn call_once_force(&self, func: impl FnOnce()) {
        // will trigger multiple initialization error if multiple versions selected
        let done: bool;
        #[cfg(spin_version = "v0_10")]
        {
            assert!(!LEGACY_POISON_BEHAVIOR);
            done = true;
            self.raw.call_once_force(|| func())
        }
        #[cfg(spin_version = "v0_9")]
        {
            assert!(LEGACY_POISON_BEHAVIOR);
            done = true;
            self.raw.call_once(func)
        }
        // will trigger a compile error if no version selected
        assert!(!done, "unsupported spin version")
    }
}