//! This crate adds the missing Option::inspect function via an extension trait //! pub trait OptionInspect where F: FnOnce(&T), T: Sized { fn inspect(self, f: F) -> Self; } pub trait OptionInspectRef where F: FnOnce(&T), T: Sized { fn inspect(&self, f: F); } impl OptionInspect for Option where F: FnOnce(&T), T: Sized { fn inspect(self, f: F) -> Self { if let Some(ref o) = self.as_ref() { (f)(&o); } self } } impl OptionInspectRef for Option where F: FnOnce(&T), T: Sized { fn inspect(&self, f: F) { if let Some(ref o) = self { (f)(&o); } } }