about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authoraochagavia <aochagavia92@gmail.com>2014-03-16 12:11:13 +0100
committeraochagavia <aochagavia92@gmail.com>2014-03-16 12:11:13 +0100
commitea8da6ed9743eb6cf047a1080c711bdceec93375 (patch)
tree0d6181cee0097f34fded93b0b4877c4ebffd0fa6 /src/libstd
parentd956975e7d92f56ebfa6133c45af62d024b888df (diff)
downloadrust-ea8da6ed9743eb6cf047a1080c711bdceec93375.tar.gz
rust-ea8da6ed9743eb6cf047a1080c711bdceec93375.zip
Refactored take_unwrap (libstd/option.rs)
Using pattern matching instead of is_some + unwrap
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/option.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index b70c8e17259..e4d843d8882 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -311,10 +311,10 @@ impl<T> Option<T> {
     /// 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.