From 49346dc963e27049ae5564692b197af3beb1c2e9 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Sat, 22 Oct 2022 14:23:39 -0400 Subject: removed `unwrap_or` and `unwrap_or_default` --- src/lib.rs | 57 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) (limited to 'src/lib.rs') 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 Expect { /// /// 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 Expect { 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 = Expected(9); - /// assert_eq!(x.unwrap_or(default), 9); - /// - /// let x: Expect = 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 E>(self, op: F) -> E { - match self { - Expected(e) => e, - Unexpected(u) => op(u), - } - } } -- cgit v1.2.3