Struct global::Global

source ·
pub struct Global<T> { /* private fields */ }
Expand description

A global value.

All types wrapped in Global must implement Default. This gives the initial value of the global variable.

Handles to this value can be obtained with the Global::lock or Global::lock_mut methods.

Implementations§

The initial global value.

The docs here will show you the internals of Global::INIT, however this is not intended to be visible. Once const fn is stabilized, this will become a const fn.

A non-constant version of Global::INIT.

Prefer the constant value where possible.

Run a closure on an immutable reference to the inner value.

This will return the closure’s return type. Internally, lock is called and unwrapped.

Panics

This will panic if the value is already borrowed mutably in the same thread.

Run a closure on a mutable reference to the inner value.

This will return the closure’s return type. Internally, lock_mut is called and unwrapped.

Panics

This will panic if the value is already borrowed either mutably or immutably in the same thread.

Obtain a lock providing an immutable reference to the inner value0.

This method will block the current thread until any other threads holding a lock are destroyed. If the current thread already has mutable access, this method will return an error.

Obtain a lock providing a mutable reference to the inner value0.

This method will block the current thread until any other threads holding a lock are destroyed. If the current thread already has access, whether mutable or immutable, this method will return an error.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.