std_lib/
async_fn_trait.rs1use std::future::Future;
2
3pub trait AsyncFnOnce<Args> {
4 type Output;
5 type Future: Future<Output = Self::Output> + Send;
6 fn call_once(self, _: Args) -> Self::Future;
7}
8
9pub trait AsyncFnMut<Args>: AsyncFnOnce<Args> {
10 fn call_mut(&mut self, args: Args) -> Self::Future;
11}
12
13pub trait AsyncFn<Args>: AsyncFnMut<Args> {
14 fn call(&self, args: Args) -> Self::Future;
15}
16
17impl<Func, Args> AsyncFnOnce<Args> for Func
18where
19 Func: crate::fn_trait::FnOnce<Args>,
20 Func::Output: Future + Send,
21{
22 type Output = <Func::Output as Future>::Output;
23 type Future = Func::Output;
24
25 fn call_once(self, args: Args) -> Self::Future {
26 Func::call_once(self, args)
27 }
28}
29
30impl<Func, Args> AsyncFnMut<Args> for Func
31where
32 Func: crate::fn_trait::FnMut<Args>,
33 Func::Output: Future + Send,
34{
35 fn call_mut(&mut self, args: Args) -> Self::Future {
36 Func::call_mut(self, args)
37 }
38}
39
40impl<Func, Args> AsyncFn<Args> for Func
41where
42 Func: crate::fn_trait::Fn<Args>,
43 Func::Output: Future + Send,
44{
45 fn call(&self, args: Args) -> Self::Future {
46 Func::call(self, args)
47 }
48}