pub struct RefCountedSingleton<T>(/* private fields */);
Expand description
A reference-counted singleton whose protected data can be recreated as needed.
The protected data is created when RefCountedSingleton::get_or_init
is called.
That function returns an RCSRef
reference to the singleton.
RCSRef
instances can be cloned as needed.
The last RCSRef
reference drops the data.
Calling RefCountedSingleton::get_or_init
again recreates the data.
Implementations§
source§impl<T> RefCountedSingleton<T>
impl<T> RefCountedSingleton<T>
sourcepub fn get_or_init<E: Error>(
&self,
creator: impl FnOnce() -> Result<T, E>
) -> Result<RCSRef<'_, T>, Option<E>>
pub fn get_or_init<E: Error>( &self, creator: impl FnOnce() -> Result<T, E> ) -> Result<RCSRef<'_, T>, Option<E>>
Return a counted reference to the protected data if such data exists,
otherwise creates a new instance of the data by calling creator()
.
If the lock is poisoned, then this returns Err(None)
.
If creator()
returns an error err
, then this returns
Err(Some(err))
.
Trait Implementations§
source§impl<T: Debug> Debug for RefCountedSingleton<T>
impl<T: Debug> Debug for RefCountedSingleton<T>
Auto Trait Implementations§
impl<T> !Freeze for RefCountedSingleton<T>
impl<T> RefUnwindSafe for RefCountedSingleton<T>
impl<T> Send for RefCountedSingleton<T>
impl<T> Sync for RefCountedSingleton<T>
impl<T> Unpin for RefCountedSingleton<T>
impl<T> UnwindSafe for RefCountedSingleton<T>
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