| 1 | /// Async equivalent of [`Drop`]. |
| 2 | /// |
| 3 | /// This trait is similar to [`Drop`], but it is async so types that need to perform async |
| 4 | /// operations when they're dropped should implement this. Unfortunately, the `async_drop` method |
| 5 | /// won't be implicitly called by the compiler for the user so types implementing this trait will |
| 6 | /// also have to implement [`Drop`] to clean up (for example, by passing the async cleanup to |
| 7 | /// another async task). This is also why the `async_drop` method consumes `self` instead of taking |
| 8 | /// a `&mut self` like [`Drop`]. |
| 9 | /// |
| 10 | /// Hopefully this will be unnecessary [in the future][itf] when Rust gain an `AsyncDrop` itself. |
| 11 | /// |
| 12 | /// [itf]: https://rust-lang.github.io/async-fundamentals-initiative/roadmap/async_drop.html |
| 13 | #[async_trait::async_trait ] |
| 14 | pub trait AsyncDrop { |
| 15 | /// Perform the async cleanup. |
| 16 | async fn async_drop(self); |
| 17 | } |
| 18 | |