小编Nig*_*Str的帖子

从 `async fn` 返回的 future 的具体类型是什么?

我应该使用什么类型的向量来存储 future?

我尝试在同一个 URL 上发出多个并发请求,并将所有 future 保存到向量中以与join_all.

如果我没有明确设置向量的类型,则一切正常。我知道 Rust 可以找到变量的正确类型。CLion 确定向量类型为Vec<dyn Future<Output = ()>>,但是当我尝试自己设置类型时,它给了我一个错误:

error[E0277]: the size for values of type `dyn core::future::future::Future<Output = ()>` cannot be known at compilation time
  --> src/lib.rs:15:23
   |
15 |     let mut requests: Vec<dyn Future<Output = ()>> = Vec::new();
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `dyn core::future::future::Future<Output = ()>`
   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = …
Run Code Online (Sandbox Code Playgroud)

asynchronous future rust

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

asynchronous ×1

future ×1

rust ×1