1#![no_std]
2#![doc = include_str!("../README.md")]
3
4#[cfg(all(feature = "std"))]
5#[allow(dead_code)] pub(crate) mod fallback;
7pub mod namespace;
8pub mod once;
9
10pub use bytemuck::{Pod, Zeroable};
11pub use namespace::{Namespace, NamespaceExt};
12pub use once::OnceSlot;
13
14define_namespace!(pub DefaultNamespace);
15
16#[inline(always)]
26#[must_use]
27pub fn get<T>() -> &'static T
28where
29 T: 'static + Zeroable,
30{
31 <DefaultNamespace as Namespace>::generic_static::<T>()
32}
33
34#[inline(always)]
36#[must_use]
37pub fn get_in<NS, T>() -> &'static T
38where
39 NS: Namespace,
40 T: 'static + Zeroable,
41{
42 <NS as Namespace>::generic_static::<T>()
43}
44
45#[inline(always)]
53pub unsafe fn get_mut<T>() -> *mut T
54where
55 T: 'static + Zeroable,
56{
57 unsafe { <DefaultNamespace as Namespace>::generic_static_mut::<T>() }
59}
60
61#[inline(always)]
67pub unsafe fn get_in_mut<NS, T>() -> *mut T
68where
69 NS: Namespace,
70 T: 'static + Zeroable,
71{
72 unsafe { <NS as Namespace>::generic_static_mut::<T>() }
74}
75
76#[inline(always)]
78#[must_use]
79pub fn get_const<T, const N: usize>() -> &'static T
80where
81 T: 'static + Zeroable,
82{
83 <DefaultNamespace as Namespace>::generic_static_const::<T, N>()
84}
85
86#[inline(always)]
88#[must_use]
89pub fn get_in_const<NS, T, const N: usize>() -> &'static T
90where
91 NS: Namespace,
92 T: 'static + Zeroable,
93{
94 <NS as Namespace>::generic_static_const::<T, N>()
95}
96
97#[inline(always)]
103pub unsafe fn get_const_mut<T, const N: usize>() -> *mut T
104where
105 T: 'static + Zeroable,
106{
107 unsafe { <DefaultNamespace as Namespace>::generic_static_const_mut::<T, N>() }
109}
110
111#[inline(always)]
117pub unsafe fn get_in_const_mut<NS, T, const N: usize>() -> *mut T
118where
119 NS: Namespace,
120 T: 'static + Zeroable,
121{
122 unsafe { <NS as Namespace>::generic_static_const_mut::<T, N>() }
124}
125
126#[must_use]
138pub fn once<T>(init: impl FnOnce() -> T) -> &'static T
139where
140 T: 'static + Send + Sync,
141{
142 <DefaultNamespace as NamespaceExt>::once(init)
143}
144
145#[must_use]
147pub fn once_const<T, const N: usize>(init: impl FnOnce() -> T) -> &'static T
148where
149 T: 'static + Send + Sync,
150{
151 <DefaultNamespace as NamespaceExt>::once_const::<T, N>(init)
152}