obrewin_utils/
bam.rs

1use std::future::Future;
2
3/// BAM is an abbreviated name of "BoxedAsyncMethod".
4/// It represents an async method that gets one
5/// parameter and returns a boxed async future.
6pub type BAM<'se, T, R> = Box<dyn Fn(T) -> Box<dyn Future<Output = R> + 'se> + 'se>;
7
8/// Similar to `Into<BAM<..>>`.
9pub trait IntoBAM<'se, T, R> {
10    /// Convert this object into `BAM`.
11    fn into_bam(self) -> BAM<'se, T, R>;
12}
13
14impl<'se, T, R, C, Fut> IntoBAM<'se, T, R> for C
15where
16    C: Fn(T) -> Fut + 'se,
17    Fut: Future<Output = R> + 'se,
18{
19    fn into_bam(self) -> BAM<'se, T, R> {
20        Box::new(move |parameter: T| Box::new(self(parameter)))
21    }
22}