From deb1544bc566b3117a97b72ee2d98efdbba58616 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 30 Jul 2016 11:45:31 +0200 Subject: [PATCH] Add info_result --- libimagutil/src/info_result.rs | 28 ++++++++++++++++++++++++++++ libimagutil/src/lib.rs | 1 + 2 files changed, 29 insertions(+) create mode 100644 libimagutil/src/info_result.rs 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;