我希望以下代码中的异步块实现Send(Playground):
use std::collections::BTreeSet;
use std::future::ready;
pub fn test<T: Sync>(set: &BTreeSet<T>) -> impl Send + '_ {
async move {
for _ in set {
ready(()).await;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但它给出了以下错误:
Compiling playground v0.0.1 (/playground)
error[E0311]: the parameter type `T` may not live long enough
--> src/lib.rs:4:44
|
4 | pub fn test<T: Sync>(set: &BTreeSet<T>) -> impl Send + '_ {
| -- ^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
| |
| …Run Code Online (Sandbox Code Playgroud)