pub struct Storage { /* private fields */ }Expand description
An storage implementation for singleton design pattern, where we only have one value associated with each types.
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn with<T: 'static + Default, U, F: FnOnce(&T) -> U>(
&mut self,
callback: F,
) -> U
pub fn with<T: 'static + Default, U, F: FnOnce(&T) -> U>( &mut self, callback: F, ) -> U
Pass an immutable reference to the stored data of the type T to the closure,
if there is no data associated with the type, store the Default and then perform the
operation.
Sourcepub fn maybe_with<T: 'static, U, F: FnOnce(&T) -> U>(
&mut self,
callback: F,
) -> Option<U>
pub fn maybe_with<T: 'static, U, F: FnOnce(&T) -> U>( &mut self, callback: F, ) -> Option<U>
Pass an immutable reference to the stored data of the type T to the closure,
if there is no data associated with the type, just return None.
Sourcepub fn with_mut<T: 'static + Default, U, F: FnOnce(&mut T) -> U>(
&mut self,
callback: F,
) -> U
pub fn with_mut<T: 'static + Default, U, F: FnOnce(&mut T) -> U>( &mut self, callback: F, ) -> U
Like Self::with but passes a mutable reference.
Sourcepub fn maybe_with_mut<T: 'static, U, F: FnOnce(&mut T) -> U>(
&mut self,
callback: F,
) -> Option<U>
pub fn maybe_with_mut<T: 'static, U, F: FnOnce(&mut T) -> U>( &mut self, callback: F, ) -> Option<U>
Like Self::maybe_with but passes a mutable reference.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Storage
impl !RefUnwindSafe for Storage
impl !Send for Storage
impl !Sync for Storage
impl Unpin for Storage
impl !UnwindSafe for Storage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more