Add utility to print debugging information while mapping
This commit is contained in:
parent
b2c11384c0
commit
0b1ea94dae
2 changed files with 29 additions and 0 deletions
28
libimagutil/src/debug_result.rs
Normal file
28
libimagutil/src/debug_result.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
pub trait DebugResult<T, E> : Sized {
|
||||
|
||||
fn map_dbg<F: FnOnce(&T) -> String>(self, f: F) -> Self;
|
||||
|
||||
fn map_dbg_str(self, s: &str) -> Self {
|
||||
self.map_dbg(|_| format!("{}", s))
|
||||
}
|
||||
|
||||
fn map_dbg_err<F: FnOnce(&E) -> String>(self, f: F) -> Self;
|
||||
|
||||
fn map_dbg_err_str(self, s: &str) -> Self {
|
||||
self.map_dbg_err(|_| format!("{}", s))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<T, E> DebugResult<T, E> for Result<T, E> {
|
||||
|
||||
fn map_dbg<F: FnOnce(&T) -> String>(self, f: F) -> Self {
|
||||
self.map(|t| { debug!("{}", f(&t)); t })
|
||||
}
|
||||
|
||||
fn map_dbg_err<F: FnOnce(&E) -> String>(self, f: F) -> Self {
|
||||
self.map_err(|e| { debug!("{}", f(&e)); e })
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
#[macro_use] extern crate log;
|
||||
extern crate regex;
|
||||
|
||||
pub mod debug_result;
|
||||
pub mod ismatch;
|
||||
pub mod iter;
|
||||
pub mod key_value_split;
|
||||
|
|
Loading…
Reference in a new issue