/// Generic trait to enable chainable API pub trait With: Sized { /// Calls the given closure on `self`. fn with(mut self, f: F) -> Self { f(&mut self); self } /// Calls the given closure on `self`. fn try_with(mut self, f: F) -> Result where F: FnOnce(&mut Self) -> Result<(), E>, { f(&mut self)?; Ok(self) } /// Calls the given closure if `condition == true`. fn with_if(mut self, condition: bool, f: F) -> Self where F: FnOnce(&mut Self), { if condition { f(&mut self); } self } } impl With for T {}