Struct AsyncDropGuard

Source
pub struct AsyncDropGuard<T: Debug>(/* private fields */);
Expand description

AsyncDropGuard allows async dropping of the contained value with a safety check.

Values wrapped in AsyncDropGuard offer an async AsyncDropGuard::async_drop function that can be called to asynchronously drop the value. You must always manually call AsyncDropGuard::async_drop. If the AsyncDropGuard leaves scope without a call to AsyncDropGuard::async_drop, a safety check will trigger and cause a panic.

Types wrapped in AsyncDropGuard must implement AsyncDrop to define what exactly should happen when AsyncDropGuard::async_drop gets called.

Warning: If a type T is supposed to be used with AsyncDropGuard, you must ensure that there is no way to create instances of T that aren’t wrapped in AsyncDropGuard. Ideally, T’s constructor directly creates an AsyncDropGuard[T]. If a T object exists without being wrapped in AsyncDropGuard, the safety check will not run and call sites might forget to correctly drop T.

Implementations§

Source§

impl<T: Debug> AsyncDropGuard<T>

Source

pub fn new(v: T) -> Self

Wrap a value into an AsyncDropGuard. This enables the safety checks and will enforce that AsyncDropGuard::async_drop gets called before the AsyncDropGuard instance leaves scope.

Source

pub fn into_box(self) -> AsyncDropGuard<Box<T>>

Source

pub fn map_unsafe<U: Debug>(self, fun: impl FnOnce(T) -> U) -> AsyncDropGuard<U>

Source§

impl<T: Debug + AsyncDrop> AsyncDropGuard<T>

Source

pub async fn async_drop(&mut self) -> Result<(), T::Error>

Asynchronously drop the value. This will call AsyncDrop::async_drop_impl on the contained value. Calling code must ensure that the self value is dropped after this is called.

If this function does not get executed and the AsyncDropGuard instance leaves scope, that will cause a panic.

Trait Implementations§

Source§

impl<T: Debug + Debug> Debug for AsyncDropGuard<T>

Source§

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

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

impl<T: Debug> Deref for AsyncDropGuard<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: Debug> DerefMut for AsyncDropGuard<T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<T: Debug> Drop for AsyncDropGuard<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AsyncDropGuard<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AsyncDropGuard<T>
where T: RefUnwindSafe,

§

impl<T> Send for AsyncDropGuard<T>
where T: Send,

§

impl<T> Sync for AsyncDropGuard<T>
where T: Sync,

§

impl<T> Unpin for AsyncDropGuard<T>
where T: Unpin,

§

impl<T> UnwindSafe for AsyncDropGuard<T>
where T: UnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.