[][src]Struct restor::MutexStorage

pub struct MutexStorage { /* fields omitted */ }

The storage with interior mutability based on Mutexes. This allows the data that is put in to only need to be T: Send, because this only allows one thread to read or write to the data.

Because of the above, this also only has the mutable versions of functions implemented, as though a MutexGuard can only contain a mutable reference due to the nature of the mutex.

Please note!

The documentation for the functions implemented for this type are found in BlackBox's documentation under the same name.

This can be used in any context a DynamicStorage can be used with the exception of the uses of non-mut functions Please refer to the make_storage macro to create these with a shorthand.


Implementation note

A wrapper for a Mutex-safe BlackBox.

This only allows for allocation of T: Send + Any units, making it safe to impl Sync for MutexStorage.

This is done by Derefing into the appropriate BlackBox, but not DerefMuting into it. This prevents the user from using the allocate_for function from BlackBox and instead forces them to use MutexStorage's allocate_for function, which satisfies the above requirements.

This fits into the same context as any storage type provided by restor.

Methods

impl MutexStorage[src]

pub fn allocate_for<T: Send + Any>(&mut self)[src]

Adds a storage unit for the given type. This will not add another unit in the case that it already exists.

pub fn has_unit<T: Send + Any>(&self) -> bool[src]

Please refer to the documentation for this function at BlackBox::has_unit.

pub fn insert<T: Send + Any>(&self, data: T) -> Result<(), (T, ErrorDesc)>[src]

Please refer to the documentation for this function at BlackBox::insert.

pub fn insert_many<T: Send + Any>(
    &self,
    data: Vec<T>
) -> Result<(), (Vec<T>, ErrorDesc)>
[src]

Please refer to the documentation for this function at BlackBox::insert_many.

pub fn run_for_mut<T: Send + Any, D: 'static + Any, F: FnMut(&mut Vec<T>) -> D>(
    &self,
    f: F
) -> Result<D, ErrorDesc>
[src]

Please refer to the documentation for this function at BlackBox::run_for_mut.

pub fn get<'a, T: FetchMultiple<'a, dyn Unit<'u, Borrowed = MappedMutexGuard<'u, dyn Any>, MutBorrowed = MappedMutexGuard<'u, dyn Any>> + Send + Sync>>(
    &'a self
) -> Result<T::Output, ErrorDesc> where
    <T as FetchMultiple<'a, dyn Unit<'u, Borrowed = MappedMutexGuard<'u, dyn Any>, MutBorrowed = MappedMutexGuard<'u, dyn Any>> + Send + Sync>>::Actual: Send + Any
[src]

Please refer to the documentation for this function at BlackBox::get.

impl MutexStorage[src]

pub fn waiting_get<'a, T: FetchMultiple<'a, dyn Unit<'u, Borrowed = MappedMutexGuard<'u, dyn Any>, MutBorrowed = MappedMutexGuard<'u, dyn Any>> + Send + Sync>>(
    &'a self
) -> Result<T::Output, ErrorDesc> where
    <dyn Unit<'u, Borrowed = MappedMutexGuard<'u, dyn Any>, MutBorrowed = MappedMutexGuard<'u, dyn Any>> + Send + Sync as Unit<'a>>::Borrowed: Waitable,
    <dyn Unit<'u, Borrowed = MappedMutexGuard<'u, dyn Any>, MutBorrowed = MappedMutexGuard<'u, dyn Any>> + Send + Sync as Unit<'a>>::MutBorrowed: Waitable,
    <T as FetchMultiple<'a, dyn Unit<'u, Borrowed = MappedMutexGuard<'u, dyn Any>, MutBorrowed = MappedMutexGuard<'u, dyn Any>> + Send + Sync>>::Actual: Send + Any
[src]

Please refer to the documentation for this function at BlackBox::waiting_get.

impl MutexStorage[src]

pub fn new() -> Self[src]

Trait Implementations

impl Default for MutexStorage[src]

Auto Trait Implementations

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> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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