deadpool_sync

Struct SyncWrapper

Source
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,

Source

pub async fn new<F, E>(runtime: Runtime, f: F) -> Result<Self, E>
where F: FnOnce() -> Result<T, E> + Send + 'static, E: Send + 'static,

Creates a new wrapped object.

Source

pub async fn interact<F, R>(&self, f: F) -> Result<R, InteractError>
where F: FnOnce(&mut T) -> R + Send + 'static, R: Send + 'static,

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.

Source

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.

Source

pub fn lock( &self, ) -> Result<SyncGuard<'_, T>, PoisonError<MutexGuard<'_, Option<T>>>>

Lock the underlying mutex and return a guard for the inner object.

Source

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>
where T: Debug + Send + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for SyncWrapper<T>
where T: Send + 'static,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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> 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.