Crate unwrap_display

source ·
Expand description

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.

Traits

  • A type implementing this trait provides the unwrap_display method