I'm using this code:
let players: Vec<Player> = players_to_create .iter() .map(|o| Player::new(&o.id, &o.team_id, &o.name)?) .collect(); but I'm geting this error:
error[E0277]: the `?` operator can only be used in a closure that returns `Result` or `Option` (or another type that implements `FromResidual`) --> src/main.rs:17:57 | 17 | .map(|o| Player::new(&o.id, &o.team_id, &o.name)?) | --- ^ cannot use the `?` operator in a closure that returns `Player` | | | this function should return `Result` or `Option` to accept `?` | = help: the trait `FromResidual<Result<Infallible, ()>>` is not implemented for `Player` If I remove the ? I get the following error:
error[E0277]: a value of type `Vec<Player>` cannot be built from an iterator over elements of type `Result<Player, ()>` --> src/main.rs:15:32 | 15 | let players: Vec<Player> = players_to_create | ________________________________^ 16 | | .iter() 17 | | .map(|o| Player::new(&o.id, &o.team_id, &o.name)) | |_________________________________________________________^ value of type `Vec<Player>` cannot be built from `std::iter::Iterator<Item=Result<Player, ()>>` 18 | .collect(); | ------- required by a bound introduced by this call | = help: the trait `FromIterator<Result<Player, ()>>` is not implemented for `Vec<Player>` = help: the trait `FromIterator<T>` is implemented for `Vec<T>` note: required by a bound in `collect` Can you help me understand?