Skip to content

Commit

Permalink
Refactored take_unwrap (libstd/option.rs)
Browse files Browse the repository at this point in the history
Using pattern matching instead of is_some + unwrap
  • Loading branch information
aochagavia committed Mar 16, 2014
1 parent d956975 commit ea8da6e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/libstd/option.rs
Expand Up @@ -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.
Expand Down

9 comments on commit ea8da6e

@bors
Copy link
Contributor

@bors bors commented on ea8da6e Mar 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ea8da6e Mar 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging aochagavia/rust/option-take_unwrap = ea8da6e into auto

@bors
Copy link
Contributor

@bors bors commented on ea8da6e Mar 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aochagavia/rust/option-take_unwrap = ea8da6e merged ok, testing candidate = 62577b4a

@bors
Copy link
Contributor

@bors bors commented on ea8da6e Mar 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ea8da6e Mar 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging aochagavia/rust/option-take_unwrap = ea8da6e into auto

@bors
Copy link
Contributor

@bors bors commented on ea8da6e Mar 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aochagavia/rust/option-take_unwrap = ea8da6e merged ok, testing candidate = 9e89ffc

@bors
Copy link
Contributor

@bors bors commented on ea8da6e Mar 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9e89ffc

Please sign in to comment.