async_defer/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use async_io::Timer;
4use std::{fmt::Display, time::Duration};
5
6mod async_fn;
7mod caller;
8mod defer;
9mod defer_mut;
10mod dispatcher;
11mod locks;
12mod summoner;
13
14pub use caller::Caller;
15pub use dispatcher::Dispatcher;
16pub use locks::{LockMut, LockRef};
17pub use summoner::Summoner;
18pub use {async_channel, async_lock};
19
20async fn sleep(duration: Duration) {
21    Timer::after(duration).await;
22}
23
24/// Supported method return types
25pub trait ReturnType: Sized {
26    /// Called on the return value when the method returns
27    fn log(self) {}
28}
29
30impl ReturnType for () {}
31impl ReturnType for Option<()> {}
32
33impl<E: Display> ReturnType for Result<(), E> {
34    fn log(self) {
35        if let Err(message) = self {
36            log::error!("{}", message);
37        }
38    }
39}