1#![no_std]
2#![doc = include_str!("../README.md")]
3#![cfg_attr(
4 all(feature = "nightly", target_family = "wasm", target_arch = "wasm32"),
5 feature(asm_experimental_arch)
6)]
7
8#[cfg(all(feature = "std"))]
9#[allow(dead_code)]
10pub(crate) mod fallback;
11pub mod namespace;
12pub mod once;
13
14pub use bytemuck::{Pod, Zeroable};
15pub use namespace::{Namespace, NamespaceExt};
16pub use once::OnceSlot;
17
18define_namespace!(pub DefaultNamespace);
19
20#[inline(always)]
30#[must_use]
31pub fn get<T>() -> &'static T
32where
33 T: 'static + Zeroable,
34{
35 <DefaultNamespace as Namespace>::generic_static::<T>()
36}
37
38#[inline(always)]
40#[must_use]
41pub fn get_in<NS, T>() -> &'static T
42where
43 NS: Namespace,
44 T: 'static + Zeroable,
45{
46 <NS as Namespace>::generic_static::<T>()
47}
48
49#[inline(always)]
57pub unsafe fn get_mut<T>() -> *mut T
58where
59 T: 'static + Zeroable,
60{
61 unsafe { <DefaultNamespace as Namespace>::generic_static_mut::<T>() }
63}
64
65#[inline(always)]
71pub unsafe fn get_in_mut<NS, T>() -> *mut T
72where
73 NS: Namespace,
74 T: 'static + Zeroable,
75{
76 unsafe { <NS as Namespace>::generic_static_mut::<T>() }
78}
79
80#[inline(always)]
82#[must_use]
83pub fn get_const<T, const N: usize>() -> &'static T
84where
85 T: 'static + Zeroable,
86{
87 <DefaultNamespace as Namespace>::generic_static_const::<T, N>()
88}
89
90#[inline(always)]
92#[must_use]
93pub fn get_in_const<NS, T, const N: usize>() -> &'static T
94where
95 NS: Namespace,
96 T: 'static + Zeroable,
97{
98 <NS as Namespace>::generic_static_const::<T, N>()
99}
100
101#[inline(always)]
107pub unsafe fn get_const_mut<T, const N: usize>() -> *mut T
108where
109 T: 'static + Zeroable,
110{
111 unsafe { <DefaultNamespace as Namespace>::generic_static_const_mut::<T, N>() }
113}
114
115#[inline(always)]
121pub unsafe fn get_in_const_mut<NS, T, const N: usize>() -> *mut T
122where
123 NS: Namespace,
124 T: 'static + Zeroable,
125{
126 unsafe { <NS as Namespace>::generic_static_const_mut::<T, N>() }
128}
129
130#[must_use]
142pub fn once<T>(init: impl FnOnce() -> T) -> &'static T
143where
144 T: 'static + Send + Sync,
145{
146 <DefaultNamespace as NamespaceExt>::once(init)
147}
148
149#[must_use]
151pub fn once_const<T, const N: usize>(init: impl FnOnce() -> T) -> &'static T
152where
153 T: 'static + Send + Sync,
154{
155 <DefaultNamespace as NamespaceExt>::once_const::<T, N>(init)
156}