Skip to main content

Converting errors with From and ?

`?` does more than return early: it converts the error into the function's error type using `From`. Implement `From<OtherError> for MyError` once and every `?` in the module starts working.

That is what keeps application code flat. Without it you would be writing a `map_err` on every fallible call.

For quick programs and prototypes, `Box<dyn Error>` accepts any error type at all and is a perfectly respectable return type for `main`.

Run it and change it

The editor below is live: edit anything and the real compiler output updates by itself.

Your Rust