Expand description
Async drop support for Rust.
This crate provides AsyncDrop, a trait for types that need to perform
asynchronous cleanup, and Dropper, a wrapper that automatically runs
the async cleanup when the value is dropped.
§Example
use async_drop::{AsyncDrop, AsyncDropFuture, Dropper};
struct DbConnection;
impl AsyncDrop for DbConnection {
fn async_drop(&mut self) -> AsyncDropFuture<'_> {
Box::pin(async {
// Close the connection gracefully...
Ok(())
})
}
}
let conn = Dropper::new(DbConnection);
// Use `conn` as if it were a `DbConnection` (via Deref).
// When `conn` goes out of scope, `async_drop` runs automatically.Structs§
- Dropper
- A wrapper that calls
AsyncDrop::async_dropwhen dropped.
Traits§
- Async
Drop - A trait for types that require asynchronous cleanup.
Type Aliases§
- Async
Drop Future - The future type returned by
AsyncDrop::async_drop.