claw_common/
diagnostic.rs1use miette::{Diagnostic, Report};
2
3pub trait UnwrapPretty {
4 type Output;
5
6 fn unwrap_pretty(self) -> Self::Output;
7}
8
9impl<T, E> UnwrapPretty for Result<T, E>
10where
11 E: Diagnostic + Sync + Send + 'static,
12{
13 type Output = T;
14
15 fn unwrap_pretty(self) -> Self::Output {
16 match self {
17 Ok(output) => output,
18 Err(diagnostic) => {
19 panic!("{:?}", Report::new(diagnostic));
20 }
21 }
22 }
23}
24
25pub trait OkPretty {
26 type Output;
27
28 fn ok_pretty(self) -> Option<Self::Output>;
29}
30
31impl<T, E> OkPretty for Result<T, E>
32where
33 E: Diagnostic + Sync + Send + 'static,
34{
35 type Output = T;
36
37 fn ok_pretty(self) -> Option<Self::Output> {
38 match self {
39 Ok(output) => Some(output),
40 Err(diagnostic) => {
41 println!("{:?}", Report::new(diagnostic));
42 None
43 }
44 }
45 }
46}