Skip to content

Instantly share code, notes, and snippets.

@yinheli
Created December 28, 2021 12:02
Show Gist options
  • Save yinheli/b1a26cdbc3cae13551ae0a2516372f52 to your computer and use it in GitHub Desktop.
Save yinheli/b1a26cdbc3cae13551ae0a2516372f52 to your computer and use it in GitHub Desktop.
#[cfg(test)]
mod tests_lifetime {
use std::future::Future;
async fn f(_x: &i32) {
()
}
// 写法 1
//
// "F: Fn(&i32) -> Fut," 提示这里引入了新的声明周期
// 这种要怎么标注生命周期?
//
// async fn g<F, Fut>(f: F)
// where
// F: Fn(&i32) -> Fut,
// Fut: Future<Output = ()> + Send,
// {
// let x: i32 = 3;
// f(&x).await;
// }
// #[tokio::test]
// async fn tests_lifetime1() {
// g(f).await;
// }
// 写法 2
async fn g() {
let x: i32 = 3;
f(&x).await;
}
#[tokio::test]
async fn tests_lifetime2() {
g().await;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment