Created
December 28, 2021 12:02
-
-
Save yinheli/b1a26cdbc3cae13551ae0a2516372f52 to your computer and use it in GitHub Desktop.
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
#[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