diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 40a3944b7e0..ea1bddcdb4b 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -134,7 +134,7 @@ impl Option { /// Return a consuming iterator over the possibly contained value #[inline] - pub fn consume_iter(self) -> OptionIterator { + pub fn consume(self) -> OptionIterator { OptionIterator{opt: self} } @@ -410,16 +410,18 @@ impl Zero for Option { fn is_zero(&self) -> bool { self.is_none() } } -/// Immutable iterator over an Option +/// An iterator that yields either one or zero elements pub struct OptionIterator { priv opt: Option } impl Iterator for OptionIterator { + #[inline] fn next(&mut self) -> Option { - util::replace(&mut self.opt, None) + self.opt.take() } + #[inline] fn size_hint(&self) -> (uint, Option) { match self.opt { Some(_) => (1, Some(1)), diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 5a6021d32a5..91f42edf0ae 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -94,7 +94,7 @@ impl Result { match *self { Ok(ref t) => Some(t), Err(*) => None, - }.consume_iter() + }.consume() } /// Call a method based on a previous result @@ -108,7 +108,7 @@ impl Result { match *self { Ok(*) => None, Err(ref t) => Some(t), - }.consume_iter() + }.consume() } /// Unwraps a result, yielding the content of an `Ok`.