use std::{fmt,error}; #[derive(Debug)] /// There was a non-matching file pub enum UnmatchError { Size, Data, Unknown, } impl error::Error for UnmatchError{} impl fmt::Display for UnmatchError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Size => write!(f, "size differs"), Self::Data => write!(f, "data differs"), _ => write!(f, "unknown error"), } } } pub trait ResultPrintExt { fn discard_msg(self, msg: impl AsRef) -> Option; } impl ResultPrintExt for Result where E: std::fmt::Display { fn discard_msg(self, msg: impl AsRef) -> Option { match self { Ok(v) => Some(v), Err(e) => { eprintln!("{}: {}", msg.as_ref(), e); None }, } } }