pub trait NamespaceExt: Namespace {
// Provided methods
fn get<T>() -> &'static T
where T: 'static + Zeroable { ... }
unsafe fn get_mut<T>() -> *mut T
where T: 'static + Zeroable { ... }
fn once<T>(init: impl FnOnce() -> T) -> &'static T
where T: 'static + Send + Sync { ... }
fn get_const<T, const N: usize>() -> &'static T
where T: 'static + Zeroable { ... }
unsafe fn get_const_mut<T, const N: usize>() -> *mut T
where T: 'static + Zeroable { ... }
fn once_const<T, const N: usize>(init: impl FnOnce() -> T) -> &'static T
where T: 'static + Send + Sync { ... }
}Expand description
Extensions on top of Namespace::generic_static to make using
generic statics easier.
Provided Methods§
Sourcefn get<T>() -> &'static Twhere
T: 'static + Zeroable,
fn get<T>() -> &'static Twhere
T: 'static + Zeroable,
Alias for Namespace::generic_static.
Sourcefn once<T>(init: impl FnOnce() -> T) -> &'static T
fn once<T>(init: impl FnOnce() -> T) -> &'static T
Lazily-initialized generic static for types that are not Zeroable.
Backed by crate::once::OnceSlot: the first call runs init and
later calls (with the same NS and T) return the same address.
use static_generics::{define_namespace, namespace::NamespaceExt};
define_namespace!(MyNs);
let one = MyNs::once::<String>(|| String::from("hello"));
let two = MyNs::once::<String>(|| String::from("ignored"));
assert_eq!(one.as_str(), "hello");
assert!(core::ptr::eq(one, two));Sourcefn get_const<T, const N: usize>() -> &'static Twhere
T: 'static + Zeroable,
fn get_const<T, const N: usize>() -> &'static Twhere
T: 'static + Zeroable,
Alias for Namespace::generic_static_const.
Sourceunsafe fn get_const_mut<T, const N: usize>() -> *mut Twhere
T: 'static + Zeroable,
unsafe fn get_const_mut<T, const N: usize>() -> *mut Twhere
T: 'static + Zeroable,
Sourcefn once_const<T, const N: usize>(init: impl FnOnce() -> T) -> &'static T
fn once_const<T, const N: usize>(init: impl FnOnce() -> T) -> &'static T
Lazily-initialized generic static keyed by (T, const N: usize).
Like NamespaceExt::once, but the same T with a different N
is a different address. Backed by crate::once::OnceSlot.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".