From ea8da6ed9743eb6cf047a1080c711bdceec93375 Mon Sep 17 00:00:00 2001 From: aochagavia Date: Sun, 16 Mar 2014 12:11:13 +0100 Subject: [PATCH] Refactored take_unwrap (libstd/option.rs) Using pattern matching instead of is_some + unwrap --- src/libstd/option.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstd/option.rs b/src/libstd/option.rs index b70c8e1725998..e4d843d88824d 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -311,10 +311,10 @@ impl Option { /// Fails if the value equals `None`. #[inline] pub fn take_unwrap(&mut self) -> T { - if self.is_none() { - fail!("called `Option::take_unwrap()` on a `None` value") + match self.take() { + Some(x) => x, + None => fail!("called `Option::take_unwrap()` on a `None` value") } - self.take().unwrap() } /// Gets an immutable reference to the value inside an option.