pub trait AsyncDrop {
// Required method
fn async_drop<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait;
}
Expand description
Async equivalent of Drop
.
This trait is similar to Drop
, but it is async so types that need to perform async
operations when they’re dropped should implement this. Unfortunately, the async_drop
method
won’t be implicitly called by the compiler for the user so types implementing this trait will
also have to implement Drop
to clean up (for example, by passing the async cleanup to
another async task). This is also why the async_drop
method consumes self
instead of taking
a &mut self
like Drop
.
Hopefully this will be unnecessary in the future when Rust gain an AsyncDrop
itself.