pub struct SingletonUninit<T> { /* private fields */ }Expand description
A thread-unsafe global singleton which is initially uninitialized memory.
Using this across threads is undefined behaviour.
§Panics
In debug builds, usage of this abstraction is checked for safety at runtime.
- Using this struct across threads will panic.
- Mixing mutabilty of borrows will panic (this is bypassed if you are using the pointer getters)
- Using this struct before initializing it will panic.
- Initializing the value more than once will panic. Use
replace
Implementations§
Source§impl<T> SingletonUninit<T>
impl<T> SingletonUninit<T>
pub const fn uninit() -> Self
pub const fn new(val: T) -> Self
Sourcepub fn get(&'static self) -> SinglytonRef<T>
pub fn get(&'static self) -> SinglytonRef<T>
Assumes the memory is initialized and acquires an immutable reference to the singleton.
In debug builds, this will panic if the memory is not initialized, the singleton is mutably accessed from a different thread, or a mutable reference is currently held.
Sourcepub fn get_mut(&'static self) -> SinglytonRefMut<T>
pub fn get_mut(&'static self) -> SinglytonRefMut<T>
Acquires a mutable reference to the singleton.
In debug builds, this will panic if the memory is not initialized, the singleton is mutably accessed from a different thread, or an existing mutable or immutable reference is currently held.
Sourcepub unsafe fn as_ptr(&'static self) -> *const T
pub unsafe fn as_ptr(&'static self) -> *const T
Acquires an immutable pointer to the singleton.
In debug builds, this will panic if the memory is not initialized, the singleton is mutably accessed from a different thread, or a mutable reference is currently held.
This is unsafe because the returned pointer bypasses any future borrow checking.
Sourcepub unsafe fn as_mut_ptr(&'static self) -> *mut T
pub unsafe fn as_mut_ptr(&'static self) -> *mut T
Acquires a mutable pointer to the singleton.
In debug builds, this will panic if the memory is not initialized, the singleton is mutably accessed from a different thread, or an existing mutable or immutable reference is currently held.
This is unsafe because the returned pointer bypasses any future borrow checking.