#![no_std]
#![doc = include_str!("../README.md")]
#![cfg_attr(
all(feature = "nightly", target_family = "wasm", target_arch = "wasm32"),
feature(asm_experimental_arch)
)]
#[cfg(all(feature = "std"))]
#[allow(dead_code)]
pub(crate) mod fallback;
pub mod namespace;
pub mod once;
pub use bytemuck::{Pod, Zeroable};
pub use namespace::{Namespace, NamespaceExt};
pub use once::OnceSlot;
define_namespace!(pub DefaultNamespace);
#[inline(always)]
#[must_use]
pub fn get<T>() -> &'static T
where
T: 'static + Zeroable,
{
<DefaultNamespace as Namespace>::generic_static::<T>()
}
#[inline(always)]
#[must_use]
pub fn get_in<NS, T>() -> &'static T
where
NS: Namespace,
T: 'static + Zeroable,
{
<NS as Namespace>::generic_static::<T>()
}
#[inline(always)]
pub unsafe fn get_mut<T>() -> *mut T
where
T: 'static + Zeroable,
{
unsafe { <DefaultNamespace as Namespace>::generic_static_mut::<T>() }
}
#[inline(always)]
pub unsafe fn get_in_mut<NS, T>() -> *mut T
where
NS: Namespace,
T: 'static + Zeroable,
{
unsafe { <NS as Namespace>::generic_static_mut::<T>() }
}
#[inline(always)]
#[must_use]
pub fn get_const<T, const N: usize>() -> &'static T
where
T: 'static + Zeroable,
{
<DefaultNamespace as Namespace>::generic_static_const::<T, N>()
}
#[inline(always)]
#[must_use]
pub fn get_in_const<NS, T, const N: usize>() -> &'static T
where
NS: Namespace,
T: 'static + Zeroable,
{
<NS as Namespace>::generic_static_const::<T, N>()
}
#[inline(always)]
pub unsafe fn get_const_mut<T, const N: usize>() -> *mut T
where
T: 'static + Zeroable,
{
unsafe { <DefaultNamespace as Namespace>::generic_static_const_mut::<T, N>() }
}
#[inline(always)]
pub unsafe fn get_in_const_mut<NS, T, const N: usize>() -> *mut T
where
NS: Namespace,
T: 'static + Zeroable,
{
unsafe { <NS as Namespace>::generic_static_const_mut::<T, N>() }
}
#[must_use]
pub fn once<T>(init: impl FnOnce() -> T) -> &'static T
where
T: 'static + Send + Sync,
{
<DefaultNamespace as NamespaceExt>::once(init)
}
#[must_use]
pub fn once_const<T, const N: usize>(init: impl FnOnce() -> T) -> &'static T
where
T: 'static + Send + Sync,
{
<DefaultNamespace as NamespaceExt>::once_const::<T, N>(init)
}