Created
December 21, 2022 21:41
-
-
Save Venryx/f4602fc1fbbd353b7839ed87b0f4e147 to your computer and use it in GitHub Desktop.
Extensions of the `AsyncFn` trait for use with output-types and variable numbers of arguments (see: https://stackoverflow.com/a/72851012)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::Future; | |
pub trait AsyncFn_Args0<OutputType>: Fn() -> Self::Future { | |
type Future: Future<Output = OutputType>; | |
} | |
impl<OutputType, F, Fut> AsyncFn_Args0<OutputType> for F | |
where F: Fn() -> Fut, Fut: Future<Output = OutputType> { | |
type Future = Fut; | |
} | |
pub trait AsyncFn_Args1<OutputType, Arg1>: Fn(Arg1) -> Self::Future { | |
type Future: Future<Output = OutputType>; | |
} | |
impl<OutputType, Arg1, F, Fut> AsyncFn_Args1<OutputType, Arg1> for F | |
where F: Fn(Arg1) -> Fut, Fut: Future<Output = OutputType> { | |
type Future = Fut; | |
} | |
pub trait AsyncFn_Args2<OutputType, Arg1, Arg2>: Fn(Arg1, Arg2) -> Self::Future { | |
type Future: Future<Output = OutputType>; | |
} | |
impl<OutputType, Arg1, Arg2, F, Fut> AsyncFn_Args2<OutputType, Arg1, Arg2> for F | |
where F: Fn(Arg1, Arg2) -> Fut, Fut: Future<Output = OutputType> { | |
type Future = Fut; | |
} | |
pub trait AsyncFn_Args3<OutputType, Arg1, Arg2, Arg3>: Fn(Arg1, Arg2, Arg3) -> Self::Future { | |
type Future: Future<Output = OutputType>; | |
} | |
impl<OutputType, Arg1, Arg2, Arg3, F, Fut> AsyncFn_Args3<OutputType, Arg1, Arg2, Arg3> for F | |
where F: Fn(Arg1, Arg2, Arg3) -> Fut, Fut: Future<Output = OutputType> { | |
type Future = Fut; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment