我以为我已经得到了一生'static,但现在我不确定了。
我正在尝试了解如何与 Tokio 和 Futures 合作。我的应用程序正在运行,但结构很糟糕,所以我需要分解它。这是'static我关闭的要求,我不知道如何解决。
例如,在一个main函数中,我有一个句柄并且能够spawn对其循环进行 future 操作:
let mut core = tokio_core::reactor::Core::new().unwrap();
let handle = core.handle();
let future = {
ok(())
};
Run Code Online (Sandbox Code Playgroud)
它编译;现在我想移出一些逻辑:
struct Test;
impl Test {
fn test(&self, handle: tokio_core::reactor::Handle) {
let future = {
ok(())
};
handle.spawn(future);
}
}
Run Code Online (Sandbox Code Playgroud)
它也能编译。当我的结构变得更加复杂时:
struct Test<'a> {
api: &'a Arc<Api>,
}
impl<'a> Test<'a> {
fn new(api: &'a Arc<Api>) -> Self {
Test {
api: api,
}
}
fn test(&self, msg: &telegram_bot::types::Message, …Run Code Online (Sandbox Code Playgroud)