//! This crate adds the missing Result::inspect function via an extension trait //! pub trait ResultInspect where F: FnOnce(&T), T: Sized { fn inspect(self, f: F) -> Self; } pub trait ResultInspectRef where F: FnOnce(&T), T: Sized { fn inspect(&self, f: F); } impl ResultInspect for Result where F: FnOnce(&T), T: Sized { fn inspect(self, f: F) -> Self { if let Ok(ref o) = self.as_ref() { (f)(&o); } self } } impl ResultInspectRef for Result where F: FnOnce(&T), T: Sized { fn inspect(&self, f: F) { if let Ok(ref o) = self { (f)(&o); } } } pub trait ResultInspectErr where F: FnOnce(&E), E: Sized { fn inspect_err(self, f: F) -> Self; } pub trait ResultInspectErrRef where F: FnOnce(&E), E: Sized { fn inspect_err(&self, f: F); } impl ResultInspectErr for Result where F: FnOnce(&E), E: Sized { fn inspect_err(self, f: F) -> Self { if let Err(ref e) = self.as_ref() { (f)(&e); } self } } impl ResultInspectErrRef for Result where F: FnOnce(&E), E: Sized { fn inspect_err(&self, f: F) { if let Err(ref e) = self { (f)(&e); } } }