Created
July 14, 2024 20:54
-
-
Save loverdos/e78bb60a8c4b06b4a93ef93775432e23 to your computer and use it in GitHub Desktop.
async_f_type.rs
This file contains hidden or 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 core::future::Future; | |
pub trait AsyncFn<T, R> { | |
fn call(&self, t: T) -> impl Future<Output = R>; | |
} | |
impl<F, T, R, Fut> AsyncFn<T, R> for F | |
where | |
F: Fn(T) -> Fut, | |
Fut: Future<Output = R>, | |
{ | |
fn call(&self, t: T) -> impl Future<Output = R> { | |
self(t) | |
} | |
} | |
#[allow(dead_code)] | |
async fn whatever<F, T, R>(handler: F, t: &T) -> R | |
where | |
F: for<'aa> AsyncFn<&'aa T, R>, | |
{ | |
handler.call(t).await | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment