4 ms·
I’m not sure that optimizing readability for someone unfamiliar with the language is the right tradeoff. Rust code uses a Result<T, E> type for error handling:
by wtetzner 4y ago
I’m not sure that optimizing readability for someone unfamiliar with the language is the right tradeoff.
Rust code uses a Result<T, E> type for error handling: it can either be Ok(T) or Err(E), never both.
The question mark operator tries to extract the value wrapped in Ok. If the Result is Err and not Ok, it returns the error. It’s not “hidden magic”, it’s a well-defined operator.
> I don't know Rust, but the example you've given implies I can not include "?" in the call and just ignore any errors entirely?
If you don’t unwrap the value from the result, then you still have a Result<T, E> instead of a T, and will get a type error.