我正在try 使用包含VEC的Tokio::Sprown运行一个异步任务.我从编译错误消息中得到的理解是,我没有满足生命周期界限,但我不确定实现这一界限的正确方法是什么.
use tokio::sync::mpsc as tokiompsc;
pub fn _history<T: Clone + Send + Sync>() {
let (data_tx, mut data_rx) = tokiompsc::channel::<T>(10);
tokio::spawn(async move {
let mut destinations: Vec<T> = Vec::new();
data_rx.recv();
});
}
编译器错误:
error[E0310]: the parameter type `T` may not live long enough
--> src\history_generic.rs:18:5
|
18 | / tokio::spawn(async move {
19 | | let mut destinations: Vec<T> = Vec::new();
20 | | data_rx.recv();
21 | | });
| |______^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
16 | pub fn _history<T: Clone + Send + Sync + 'static>() {
| +++++++++
我已经参考了学习铁 rust 教程,但不知道如何解决这个问题.