gpt4 book ai didi

rust - 我应该如何在 Rust 中输入 annotate collect() (错误[E0282])?

转载 作者:行者123 更新时间:2023-11-29 08:26:37 25 4
gpt4 key购买 nike

<分区>

这是来自 Rust by Example 的修改示例:

fn main() {
// let strings = vec!["tofu", "93", "18"];
let strings = vec!["93", "18"];
let possible_numbers: Result<Vec<i32>, std::num::ParseIntError> = strings
.into_iter()
.map(|s| s.parse::<i32>())
.collect();
let possible_numbers = possible_numbers.unwrap();
// [93, 18]
println!("Results: {:?}", possible_numbers);
}

playground

我怎样才能重写它,使 unwrap 与其他运算符在一个链中?

如果我只是添加 unwrap()(到那个运算符链),我会收到一个编译错误:

error[E0282]: type annotations needed, cannot infer type for `B`

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com