Created
March 29, 2024 03:16
-
-
Save rcythr/16a70560c4292eae4a45979d8163515a to your computer and use it in GitHub Desktop.
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 std::future::Future; | |
| use tokio; | |
| async fn foo(a: &i32, b: i32, c: i32) -> i32 { | |
| a + b + c | |
| } | |
| async fn generic_fn<'a, F, Fut>(f: F, a: &'a i32) -> i32 | |
| where | |
| F: Fn(&'a i32, i32, i32) -> Fut + 'a, | |
| Fut: Future<Output = i32>, | |
| { | |
| let b = 2; | |
| let c = 3; | |
| f(a, b, c).await | |
| } | |
| #[tokio::main] | |
| async fn main() { | |
| let a = 1; | |
| let result = generic_fn(foo, &a).await; | |
| println!("{}", result); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment