summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-03-07 18:14:58 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-03-07 18:14:59 +0100
commitdcc5cd0c45a932b4a69491bc0d6d79b7fff8fa02 (patch)
tree43f03e01c1546fd0abc8d1e4eb21d8afc68a128a
parent61ee13132538785edc6f8c520ca8f18fb5efb309 (diff)
Add variant for inspecting None
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/lib.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 8c2fe74..9dfe3cf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -38,3 +38,38 @@ impl<F, T> OptionInspectRef<F, T> for Option<T>
}
}
}
+
+
+pub trait OptionInspectNone<F>
+ where F: FnOnce(),
+{
+ fn inspect_none(self, f: F) -> Self;
+}
+
+pub trait OptionInspectNoneRef<F>
+ where F: FnOnce(),
+{
+ fn inspect_none(&self, f: F);
+}
+
+impl<F, T> OptionInspectNone<F> for Option<T>
+ where F: FnOnce()
+{
+ fn inspect_none(self, f: F) -> Self {
+ if let None = self.as_ref() {
+ (f)();
+ }
+
+ self
+ }
+}
+
+impl<F, T> OptionInspectNoneRef<F> for Option<T>
+ where F: FnOnce()
+{
+ fn inspect_none(&self, f: F) {
+ if let None = self {
+ (f)();
+ }
+ }
+}