Trait Singleton

Source
pub unsafe trait Singleton: StableDeref {
    type Type;

    // Required methods
    unsafe fn new() -> Self;
    fn get() -> *mut Self::Type;

    // Provided method
    fn unwrap(self) -> &'static mut Self::Type
       where Self: Sized { ... }
}
Expand description

An owned singleton: a proxy (handle) for a static mut variable

Required Associated Types§

Source

type Type

The type of the static mut variable behind this proxy

Required Methods§

Source

unsafe fn new() -> Self

Creates a new singleton

§Unsafety

It’s UB to create more than one instance of this singleton

Source

fn get() -> *mut Self::Type

Returns a pointer to the static mut variable behind this proxy

Provided Methods§

Source

fn unwrap(self) -> &'static mut Self::Type
where Self: Sized,

Consumes this singleton and returns a &'static mut reference to the variable behind it

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§