4 ms·
> that the Rust way (using '?') is a 1:1 replacement for the use-cases covered by Go error management or exceptions. It is a 1:1 replacement. I think you're t
by nindalf 2y ago
> that the Rust way (using '?') is a 1:1 replacement for the use-cases covered by Go error management or exceptions.
It is a 1:1 replacement.
I think you're thinking of the case when you have many results, and you want to deal with that array of results in various ways.
> Result implements FromIterator so that a vector of results (Vec<Result<T, E>>) can be turned into a result with a vector (Result<Vec<T>, E>). Once an Result::Err is found, the iteration will terminate.
This is one such way, but there are others - https://doc.rust-lang.org/rust-by-example/error/iter_result.html https://doc.rust-lang.org/rust-by-example/error/iter_result....
This doesn't handle every case out there, but it does handle the majority of them. If you'd like to do something more bespoke, that's an option as well.