提交 9e89ffc6 编写于 作者: B bors

auto merge of #12931 : aochagavia/rust/option-take_unwrap, r=cmr

Using pattern matching instead of is_some + unwrap
......@@ -311,10 +311,10 @@ pub fn while_some(self, f: |v: 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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册