diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -2,26 +2,29 @@ //! pub trait OptionInspect<F, T> - where F: FnOnce(&T), - T: Sized +where + F: FnOnce(&T), + T: Sized, { fn inspect(self, f: F) -> Self; } pub trait OptionInspectRef<F, T> - where F: FnOnce(&T), - T: Sized +where + F: FnOnce(&T), + T: Sized, { fn inspect(&self, f: F); } impl<F, T> OptionInspect<F, T> for Option<T> - where F: FnOnce(&T), - T: Sized +where + F: FnOnce(&T), + T: Sized, { fn inspect(self, f: F) -> Self { - if let Some(ref o) = self.as_ref() { - (f)(&o); + if let Some(o) = self.as_ref() { + (f)(o); } self @@ -29,34 +32,37 @@ impl<F, T> OptionInspect<F, T> for Option<T> } impl<F, T> OptionInspectRef<F, T> for Option<T> - where F: FnOnce(&T), - T: Sized +where + F: FnOnce(&T), + T: Sized, { fn inspect(&self, f: F) { if let Some(ref o) = self { - (f)(&o); + (f)(o); } } } - pub trait OptionInspectNone<F> - where F: FnOnce(), +where + F: FnOnce(), { fn inspect_none(self, f: F) -> Self; } pub trait OptionInspectNoneRef<F> - where F: FnOnce(), +where + F: FnOnce(), { fn inspect_none(&self, f: F); } impl<F, T> OptionInspectNone<F> for Option<T> - where F: FnOnce() +where + F: FnOnce(), { fn inspect_none(self, f: F) -> Self { - if let None = self.as_ref() { + if self.is_none() { (f)(); } @@ -65,10 +71,11 @@ impl<F, T> OptionInspectNone<F> for Option<T> } impl<F, T> OptionInspectNoneRef<F> for Option<T> - where F: FnOnce() +where + F: FnOnce(), { fn inspect_none(&self, f: F) { - if let None = self { + if self.is_none() { (f)(); } } |