1use std::{
2 convert::Infallible,
3 fmt::{Debug, Display},
4};
5
6pub trait Ignore {
7 fn ignore(self);
8}
9
10impl<T, E> Ignore for Result<T, E>
11where
12 T: Debug,
13 E: Display,
14{
15 fn ignore(self) {
16 match self {
17 Ok(x) => log::trace!("ignoring {:?}", x),
18 Err(e) => log::error!("ignoring error {}", e),
19 }
20 }
21}
22
23impl<T> Ignore for Option<T>
24where
25 T: Debug,
26{
27 fn ignore(self) {
28 if let Some(x) = self {
29 log::trace!("ignoring {:?}", x)
30 } else {
31 log::error!("ignoring a None Value")
32 }
33 }
34}
35
36pub trait SafeUnwrap {
37 type Inner;
38
39 fn safe_unwrap(self) -> Self::Inner;
40}
41
42impl<T> SafeUnwrap for Result<T, Infallible> {
43 type Inner = T;
44
45 fn safe_unwrap(self) -> Self::Inner {
46 self.unwrap_or_else(|err| match err {})
47 }
48}