pub struct SyncWrapper<T>where
T: Send + 'static,{ /* private fields */ }
Expand description
Wrapper for objects which only provides blocking functions that need to be called on a separate thread.
Access to the wrapped object is provided via the SyncWrapper::interact()
method.
Implementations§
Source§impl<T> SyncWrapper<T>where
T: Send + 'static,
impl<T> SyncWrapper<T>where
T: Send + 'static,
Sourcepub async fn new<F, E>(runtime: Runtime, f: F) -> Result<Self, E>
pub async fn new<F, E>(runtime: Runtime, f: F) -> Result<Self, E>
Creates a new wrapped object.
Sourcepub async fn interact<F, R>(&self, f: F) -> Result<R, InteractError>
pub async fn interact<F, R>(&self, f: F) -> Result<R, InteractError>
Interacts with the underlying object.
Expects a closure that takes the object as its parameter. The closure is executed in a separate thread so that the async runtime is not blocked.
Sourcepub fn is_mutex_poisoned(&self) -> bool
pub fn is_mutex_poisoned(&self) -> bool
Indicates whether the underlying Mutex
has been poisoned.
This happens when a panic occurs while interacting with the object.
Sourcepub fn lock(
&self,
) -> Result<SyncGuard<'_, T>, PoisonError<MutexGuard<'_, Option<T>>>>
pub fn lock( &self, ) -> Result<SyncGuard<'_, T>, PoisonError<MutexGuard<'_, Option<T>>>>
Lock the underlying mutex and return a guard for the inner object.
Sourcepub fn try_lock(
&self,
) -> Result<SyncGuard<'_, T>, TryLockError<MutexGuard<'_, Option<T>>>>
pub fn try_lock( &self, ) -> Result<SyncGuard<'_, T>, TryLockError<MutexGuard<'_, Option<T>>>>
Try to lock the underlying mutex and return a guard for the inner object.
Trait Implementations§
Source§impl<T> Debug for SyncWrapper<T>
impl<T> Debug for SyncWrapper<T>
Auto Trait Implementations§
impl<T> Freeze for SyncWrapper<T>
impl<T> RefUnwindSafe for SyncWrapper<T>
impl<T> Send for SyncWrapper<T>
impl<T> Sync for SyncWrapper<T>
impl<T> Unpin for SyncWrapper<T>
impl<T> UnwindSafe for SyncWrapper<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