Add info_result

This commit is contained in:
Matthias Beyer 2016-07-30 11:45:31 +02:00
parent 0b1ea94dae
commit deb1544bc5
2 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,28 @@
pub trait InfoResult<T, E> : Sized {
fn map_info<F: FnOnce(&T) -> String>(self, f: F) -> Self;
fn map_info_str(self, s: &str) -> Self {
self.map_info(|_| format!("{}", s))
}
fn map_info_err<F: FnOnce(&E) -> String>(self, f: F) -> Self;
fn map_info_err_str(self, s: &str) -> Self {
self.map_info_err(|_| format!("{}", s))
}
}
impl<T, E> InfoResult<T, E> for Result<T, E> {
fn map_info<F: FnOnce(&T) -> String>(self, f: F) -> Self {
self.map(|t| { info!("{}", f(&t)); t })
}
fn map_info_err<F: FnOnce(&E) -> String>(self, f: F) -> Self {
self.map_err(|e| { info!("{}", f(&e)); e })
}
}

View file

@ -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;