SingletonUninit

Struct SingletonUninit 

Source
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>

Source

pub const fn uninit() -> Self

Source

pub const fn new(val: T) -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn replace(&'static self, val: T)

Replaces the value in the singleton with anew.

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.

Source

pub fn init(&'static self, val: T)

Initializes the memory in the singleton.

In debug builds, this will panic if the memory is already initialized, the singleton is mutably accessed from a different thread, or an existing mutable or immutable reference is currently held.

Trait Implementations§

Auto Trait Implementations§

§

impl<T> !Freeze for SingletonUninit<T>

§

impl<T> !RefUnwindSafe for SingletonUninit<T>

§

impl<T> Send for SingletonUninit<T>
where T: Send,

§

impl<T> Unpin for SingletonUninit<T>
where T: Unpin,

§

impl<T> UnwindSafe for SingletonUninit<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.