Here's a modified example from 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);
}
How can I rewrite it such that unwrap
will be in a single chain with the other operators?
If I just add unwrap()
(to that operator chain) I receive a compile error:
error[E0282]: type annotations needed, cannot infer type for `B`