由于循环中的要求相互冲突,因此无法推断出适当的生存期

时间:2019-06-18 21:40:51

标签: rust rust-tokio

我正在尝试使用依赖于Tokio的cloud_pubsub条板箱来监听来自多个Google Cloud订阅的事件。首先,我以example为特色,它以单个主题/订阅为基础,并通过循环包含多个主题的数组在其上添加了多个主题的概念。您可以在我解决该问题的初始方法下查看:

  pub fn run<'a>(&self) {
    let topics = Arc::new(self.topics);
    tokio::run(lazy(move || {
      for topic in topics.iter() {
        topic.subscribe().map(move |subscription| {
           // Do something with the subscription
        });
      }
      Ok(())
    }));
  }
}

但是,我面临的人生问题超出了我的理解范围。 我想确保嵌套块与功能run一样存在,但是,我找不到指定它的方法。这是我为嵌套块得到的许多错误之一:


error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
  --> src/worker.rs:63:21
   |
63 |       tokio::run(lazy(move || {
   |  _____________________^
64 | |       for topic in topics.iter() {
65 | |         topic.subscribe().map(move |subscription| {
...  |
86 | |       Ok(())
87 | |     }));
   | |_____^
   |

有人可以向我解释如何标记这些嵌套块以正确告知编译器它们的生命周期吗?

由于这是开放源代码,因此我将整个file进行了介绍,以提供当前问题的整个上下文。

0 个答案:

没有答案