diff --git a/src/errors.rs b/src/errors.rs index 48b6f17..58d7806 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -23,6 +23,25 @@ where E : std::fmt::Display { } } + +/// an error which can be ignored with just a warning entry and returning the default value +pub trait IgnorableDefaultableError { + fn unwrap_or_warn_default(self, msg: &str) -> T; +} + +impl IgnorableDefaultableError for StdResult +where E : std::fmt::Display, T: Default { + fn unwrap_or_warn_default(self, msg: &str) -> T { + match self { + Ok(x) => x, + Err(e) => { + warn!("{}: {}", msg, e); + T::default() + }, + } + } +} + /// result type for codemp errors pub type Result = StdResult;