[][src]Struct global::Global

pub struct Global<T>(_);

A mutable 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.

Methods

impl<T> Global<T>[src]

pub const fn new() -> Self[src]

Construct a new instance of self.

impl<T: Default + Send + 'static> Global<T>[src]

pub fn with<F, R>(&self, f: F) -> R where
    F: FnOnce(&T) -> R, 
[src]

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.

pub fn with_mut<F, R>(&self, f: F) -> R where
    F: FnOnce(&mut T) -> R, 
[src]

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.

pub fn lock(&self) -> Result<GlobalGuard<T>, BorrowFail>[src]

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.

pub fn lock_mut(&self) -> Result<GlobalGuardMut<T>, BorrowFail>[src]

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

impl<T> Sync for Global<T> where
    T: Send
[src]

Auto Trait Implementations

impl<T> Send for Global<T> where
    T: Send

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]