Skip to main content

SharedGlobal

Struct SharedGlobal 

Source
pub struct SharedGlobal<T> { /* private fields */ }
Expand description

A global version of Shared. Use SharedGlobal::shared to get a Shared to access the contents.

Implementations§

Source§

impl<T: Send + Sync> SharedGlobal<T>

Source

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

Create a new SharedGlobal.

Source

pub const fn new_lazy(f: fn() -> T) -> Self

Create a new, lazy SharedGlobal implementation that will be initialized on the first access.

Source§

impl<T: Send> SharedGlobal<T>

Source

pub const fn new_unsync(t: T) -> Self

The SharedGlobal::new function requires a type that is both Send + Sync. If this is not possible, you may call SharedGlobal::new_unsync to create a SharedGlobal implementation that uses a [Mutex].

This will fail to compile:

// Compiler error:
// error[E0277]: (type) cannot be shared between threads safely
// required by a bound in `keepcalm::Shared::<T>::new
SharedGlobal::new(Unsync {});

This will work:

SharedGlobal::new_unsync(Unsync {});
Source

pub const fn new_lazy_unsync(f: fn() -> T) -> Self

The SharedGlobal::new_lazy function requires a type that is both Send + Sync. If this is not possible, you may call SharedGlobal::new_lazy to create a SharedGlobal implementation that uses a [Mutex].

Source

pub const fn new_mutex(t: T) -> Self

Create a new SharedGlobal, backed by a Mutex and poisoning on panic.

Source

pub const fn new_mutex_with_policy(t: T, policy: PoisonPolicy) -> Self

Create a new SharedGlobal, backed by a Mutex and optionally poisoning on panic.

Source

pub const fn shared(&'static self) -> Shared<T>

Create a Shared reference, backed by this global. Note that the Shared cannot be unwrapped.

Source

pub fn read(&'static self) -> SharedReadLock<'static, T>

Lock the global SharedGlobal for reading directly.

Source

pub const fn cast<U>(&'static self) -> Shared<U>
where T: Castable<U> + 'static, U: ?Sized + 'static,

Cast this SharedGlobal to a new type.

See Castable for more information.

Auto Trait Implementations§

§

impl<T> !Freeze for SharedGlobal<T>

§

impl<T> !RefUnwindSafe for SharedGlobal<T>

§

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

§

impl<T> Sync for SharedGlobal<T>
where T: Send,

§

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

§

impl<T> UnsafeUnpin for SharedGlobal<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for SharedGlobal<T>

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_> Castable<dyn Any> for T_
where T_: Any + 'static,

Source§

fn cast<'a>(&'a self) -> &'a (dyn Any + 'static)
where T_: 'a,

Source§

fn cast_mut<'a>(&'a mut self) -> &'a mut (dyn Any + 'static)
where T_: 'a,

Source§

impl<T_, T> Castable<dyn Borrow<T>> for T_
where T: 'static + ?Sized, T_: Borrow<T> + 'static,

Source§

fn cast<'a>(&'a self) -> &'a (dyn Borrow<T> + 'static)
where T_: 'a,

Source§

fn cast_mut<'a>(&'a mut self) -> &'a mut (dyn Borrow<T> + 'static)
where T_: 'a,

Source§

impl<T_, T> Castable<dyn BorrowMut<T>> for T_
where T: 'static + ?Sized, T_: BorrowMut<T> + 'static,

Source§

fn cast<'a>(&'a self) -> &'a (dyn BorrowMut<T> + 'static)
where T_: 'a,

Source§

fn cast_mut<'a>(&'a mut self) -> &'a mut (dyn BorrowMut<T> + 'static)
where T_: 'a,

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.