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>
impl<T: Debug> AsyncDropGuard<T>
Sourcepub fn new(v: T) -> Self
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.
pub fn into_box(self) -> AsyncDropGuard<Box<T>>
pub fn map_unsafe<U: Debug>(self, fun: impl FnOnce(T) -> U) -> AsyncDropGuard<U>
Source§impl<T: Debug + AsyncDrop> AsyncDropGuard<T>
impl<T: Debug + AsyncDrop> AsyncDropGuard<T>
Sourcepub async fn async_drop(&mut self) -> Result<(), T::Error>
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.