summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2022-10-22 14:23:39 -0400
committerBotahamec <botahamec@outlook.com>2022-10-22 14:23:39 -0400
commit49346dc963e27049ae5564692b197af3beb1c2e9 (patch)
tree00cefde1400a9a32477ad6b829cdb74472ef183a /src/lib.rs
parentf5bb265af6f69c43fb245f40da1c0af31a2c7113 (diff)
removed `unwrap_or` and `unwrap_or_default`
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs57
1 files changed, 1 insertions, 56 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a4e7d48..dcd75dd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -187,10 +187,7 @@ impl<E, U> Expect<E, U> {
///
/// Because this function may panic, its use is generally discouraged.
/// Instead, prefer to use pattern matching and handle the [`Unexpected`]
- /// case explicitly, or use [`unwrap_or`] or [`unwrap_or_else`].
- ///
- /// [`unwrap_or`]: Expect::unwrap_or
- /// [`unwrap_or_else`]: Expect::unwrap_or_else
+ /// case explicitly.
///
/// # Panics
///
@@ -260,56 +257,4 @@ impl<E, U> Expect<E, U> {
Unexpected(u) => u,
}
}
-
- /// Returns the contained [`Expected`] value, or a provided default.
- ///
- /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are
- /// passing the result of a function call, it is recommended to use
- /// [`unwrap_or_else`], which is lazily evaluated.
- ///
- /// [`unwrap_or_else`]: Expect::unwrap_or_else
- ///
- /// # Examples
- ///
- /// Basic usage:
- ///
- /// ```
- /// use exun::*;
- ///
- /// let default = 2;
- /// let x: Expect<u32, &str> = Expected(9);
- /// assert_eq!(x.unwrap_or(default), 9);
- ///
- /// let x: Expect<u32, &str> = Unexpected("unexpected");
- /// assert_eq!(x.unwrap_or(default), 2);
- /// ```
- #[allow(clippy::missing_const_for_fn)]
- pub fn unwrap_or(self, default: E) -> E {
- match self {
- Expected(e) => e,
- Unexpected(_) => default,
- }
- }
-
- /// Returns the contained [`Expected`] value, or computes it from a
- /// closure.
- ///
- /// # Examples
- ///
- /// Basic usage:
- ///
- /// ```
- /// use exun::*;
- ///
- /// fn count(x: &str) -> usize { x.len() }
- ///
- /// assert_eq!(Expected(2).unwrap_or_else(count), 2);
- /// assert_eq!(Unexpected("foo").unwrap_or_else(count), 3);
- /// ```
- pub fn unwrap_or_else<F: FnOnce(U) -> E>(self, op: F) -> E {
- match self {
- Expected(e) => e,
- Unexpected(u) => op(u),
- }
- }
}