Skip to content

Instantly share code, notes, and snippets.

@rcythr
Created March 29, 2024 03:16
Show Gist options
  • Select an option

  • Save rcythr/16a70560c4292eae4a45979d8163515a to your computer and use it in GitHub Desktop.

Select an option

Save rcythr/16a70560c4292eae4a45979d8163515a to your computer and use it in GitHub Desktop.
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