2018-12-20 16:37:08 +01:00
|
|
|
# Mapping Errors
|
2018-12-20 15:14:21 +01:00
|
|
|
|
|
|
|
Now let's get more rust idiomatic by using `.map_err()`.
|
|
|
|
|
2018-12-20 14:52:06 +01:00
|
|
|
~~~rust
|
2019-03-04 11:38:35 +01:00
|
|
|
{{#include ../examples/tutorial3.rs}}
|
2018-12-20 14:52:06 +01:00
|
|
|
# #[allow(dead_code)]
|
|
|
|
# mod chainerror {
|
2020-03-03 14:25:37 +01:00
|
|
|
{{#rustdoc_include ../src/lib.rs:-1}}
|
2018-12-20 14:52:06 +01:00
|
|
|
# }
|
2018-12-20 15:14:21 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
If you compare the output to the previous example, you will see,
|
|
|
|
that:
|
|
|
|
|
|
|
|
~~~
|
|
|
|
Error: src/main.rs:19: "func1 error"
|
|
|
|
~~~
|
|
|
|
|
|
|
|
changed to just:
|
|
|
|
|
|
|
|
~~~
|
|
|
|
src/main.rs:16: "func1 error"
|
|
|
|
~~~
|
|
|
|
|
|
|
|
This is, because we caught the error of `func1()` in `main()` and print it out ourselves.
|
|
|
|
|
|
|
|
We can now control, whether to output in `Debug` or `Display` mode.
|
|
|
|
Maybe depending on `--debug` as a CLI argument.
|