Add info_result
This commit is contained in:
parent
0b1ea94dae
commit
deb1544bc5
2 changed files with 29 additions and 0 deletions
28
libimagutil/src/info_result.rs
Normal file
28
libimagutil/src/info_result.rs
Normal 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 })
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue