diff --git a/libimagutil/src/info_result.rs b/libimagutil/src/info_result.rs new file mode 100644 index 00000000..0c40612b --- /dev/null +++ b/libimagutil/src/info_result.rs @@ -0,0 +1,28 @@ +pub trait InfoResult : Sized { + + fn map_info String>(self, f: F) -> Self; + + fn map_info_str(self, s: &str) -> Self { + self.map_info(|_| format!("{}", s)) + } + + fn map_info_err String>(self, f: F) -> Self; + + fn map_info_err_str(self, s: &str) -> Self { + self.map_info_err(|_| format!("{}", s)) + } + +} + +impl InfoResult for Result { + + fn map_info String>(self, f: F) -> Self { + self.map(|t| { info!("{}", f(&t)); t }) + } + + fn map_info_err String>(self, f: F) -> Self { + self.map_err(|e| { info!("{}", f(&e)); e }) + } + +} + diff --git a/libimagutil/src/lib.rs b/libimagutil/src/lib.rs index 0eafd4ef..a05d14e8 100644 --- a/libimagutil/src/lib.rs +++ b/libimagutil/src/lib.rs @@ -18,6 +18,7 @@ extern crate regex; pub mod debug_result; +pub mod info_result; pub mod ismatch; pub mod iter; pub mod key_value_split;