3 use std::boxed::ThinBox;
6 use std::ops::DerefMut;
8 const EXPECTED: &str = "boooo!";
11 let thin_error: ThinBox<dyn Error> = ThinBox::new_unsize(Foo);
12 assert_eq!(mem::size_of::<*const i32>(), mem::size_of_val(&thin_error));
13 let msg = thin_error.to_string();
14 assert_eq!(EXPECTED, msg);
16 let mut thin_concrete_error: ThinBox<Foo> = ThinBox::new(Foo);
17 assert_eq!(mem::size_of::<*const i32>(), mem::size_of_val(&thin_concrete_error));
18 let msg = thin_concrete_error.to_string();
19 assert_eq!(EXPECTED, msg);
20 let inner = thin_concrete_error.deref_mut();
21 let msg = inner.to_string();
22 assert_eq!(EXPECTED, msg);
28 impl fmt::Display for Foo {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 write!(f, "{}", EXPECTED)