如何明确收集itertools的矢量:: MINMAX结果?

问题描述 投票:2回答:1

我使用的是从迭代工具箱的minmax功能:

use itertools::Itertools;

let row_minmax: Vec<MinMaxResult> = input
    .into_par_iter()
    .map(|row| row.iter().minmax())
    .collect::<Vec<MinMaxResult>>();

我得到:

error[E0412]: cannot find type `MinMaxResult` in this scope
 --> src/main.rs:4:25
  |
4 |     let row_minmax: Vec<MinMaxResult> = input
  |                         ^^^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
  |
1 | use itertools::MinMaxResult;

我试着MinMaxResult更换itertools::MinMaxResult并随即变型,没有效果:

error[E0107]: wrong number of type arguments: expected 1, found 0
 --> src/main.rs:4:25
  |
4 |     let row_minmax: Vec<itertools::MinMaxResult> = input
  |                         ^^^^^^^^^^^^^^^^^^^^^^^ expected 1 type argument

我知道我可以使用Vec<_>,但我是很新的锈,所以我更喜欢明确键入的所有内容(即使它不是地道),以确保发生的事情经过我的头什么编译器正在做相关。我知道这使得代码看起来像生病了,但它可以帮助我学习。

rust
1个回答
4
投票

itertools::MinMaxResult是一个通用型。您需要可以指定类型的参数,或者使用_让编译器来推断。

let row_minmax = input
    .into_par_iter()
    .map(|row| row.iter().minmax())
    .collect::<Vec<MinMaxResult<u32>>>();
© www.soinside.com 2019 - 2024. All rights reserved.