2 releases
0.0.1 | Dec 6, 2023 |
---|---|
0.0.0 | Dec 6, 2023 |
#51 in #unwrap
Used in 2 crates
7KB
unwrap_display
Like unwrap
for Result but formats using core::fmt::Display
trait instead of core::fmt::Debug
.
This crate is most useful for tests, so I recommend adding it to the dev-dependencies
section instead of dependencies
section of the Cargo.toml
file.
[dev-dependencies]
unwrap_display = "0.0"
lib.rs
:
When an error happens, core::result::Result::unwrap
prints the error using the core::fmt::Debug
instead of the core::fmt::Display
trait.
That's ok as the result of unwrap
is not meant to be seen by end users anyway.
Some error types are also incomprehensible for developers when being formatted using Debug
instead of Display
.
In this case formatting the error with Display
can increase productivity.
A typical usecase would be errors from parsers inside unittests.
This crate adds the
unwrap_display
and
expect_display_code
methods to core::result::Result
.
Both are using the #[track_caller]
attribute to simplify debugging.
Now you can write do_something_interesting().unwrap_display()
in your tests and get the error formatted with Display
instead of Debug.