1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! # [`Dispair`]
//! Dispair (Disp-Err) is a zero-dependency (other than `std`) library that provides a simple wrapper struct that implements `Error` for any type that implements both `Debug` and `Display`.
//! ```rust
//!use dispair::Dispair;
//!use std::error::Error;
//!
//!#[derive(Debug)]
//!struct TestStruct;
//!
//!impl core::fmt::Display for TestStruct {
//! fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
//! core::fmt::Debug::fmt(&self, f)
//! }
//!}
//!
//!fn main() {
//!
//! // Wrap `TestStruct` (which doesn't implement `Error`) in `Dispair` and return it.
//! let err = Dispair(TestStruct);
//!
//! // Display just passes through to the wrapped value
//! assert_eq!(format!("{}", err), "TestStruct");
//!
//! // Debug, however, does show `Dispair`.
//! assert_eq!(format!("{:?}", err), "Dispair(TestStruct)");
//!
//! // We should be able to convert it into a `Box<dyn Error>`
//! let err_boxed: Box<dyn Error> = Box::new(err);
//!
//! // And this should print nicely
//! assert_eq!(err_boxed.to_string(), "TestStruct");
//!}
//!```
use ;
/// # [`Dispair`]
/// Wraps a given type that implements [`Display`] and [`Debug`] and implements [`Error`].
;