async_drop_guard/async_drop.rs
1use async_trait::async_trait;
2use std::fmt::Debug;
3
4/// Implement this trait to define an async drop behavior for your
5/// type. See [AsyncDropGuard] for more details.
6#[async_trait]
7pub trait AsyncDrop {
8 type Error: Debug;
9
10 /// Implement this to define drop behavior for your type.
11 /// This will be called whenever [AsyncDropGuard::async_drop] is executed
12 /// while wrapping a value of the type implementing [AsyncDrop].
13 ///
14 /// If the implementing type also implements [Drop], then [Drop::drop]
15 /// will be executed synchronously and after [AsyncDrop::async_drop_impl].
16 ///
17 /// [AsyncDrop::async_drop_impl] can return an error and that error
18 /// will be propagated to the caller of [AsyncDropGuard::async_drop_impl].
19 /// If such an error happens, [Drop::drop] still gets executed.
20 async fn async_drop_impl(&mut self) -> Result<(), Self::Error>;
21}