diff --git a/src/libcore/char.rs b/src/libcore/char.rs index f0151dda8d7..aa6028a19b3 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -446,7 +446,9 @@ enum EscapeUnicodeState { Done, } -impl Iterator for EscapeUnicode { +impl Iterator for EscapeUnicode { + type Item = char; + fn next(&mut self) -> Option { match self.state { EscapeUnicodeState::Backslash => { @@ -501,7 +503,9 @@ enum EscapeDefaultState { Unicode(EscapeUnicode), } -impl Iterator for EscapeDefault { +impl Iterator for EscapeDefault { + type Item = char; + fn next(&mut self) -> Option { match self.state { EscapeDefaultState::Backslash(c) => { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index d7a675b3104..c4b3531d539 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -82,9 +82,11 @@ use uint; /// else. #[lang="iterator"] #[unstable = "just split up for object safety"] -pub trait Iterator { +pub trait Iterator { + type Item; + /// Advance the iterator and return the next value. Return `None` when the end is reached. - fn next(&mut self) -> Option; + fn next(&mut self) -> Option; /// Returns a lower and upper bound on the remaining length of the iterator. /// @@ -98,19 +100,19 @@ pub trait Iterator { #[unstable = "may be replaced by a more general conversion trait"] pub trait FromIterator { /// Build a container with elements from an external iterator. - fn from_iter>(iterator: T) -> Self; + fn from_iter>(iterator: T) -> Self; } /// A type growable from an `Iterator` implementation #[unstable = "just renamed as part of collections reform"] pub trait Extend { /// Extend a container with the elements yielded by an arbitrary iterator - fn extend>(&mut self, iterator: T); + fn extend>(&mut self, iterator: T); } #[unstable = "new convention for extension traits"] /// An extension trait providing numerous methods applicable to all iterators. -pub trait IteratorExt: Iterator + Sized { +pub trait IteratorExt: Iterator + Sized { /// Chain this iterator with another, returning a new iterator that will /// finish iterating over the current iterator, and then iterate /// over the other specified iterator. @@ -127,7 +129,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn chain>(self, other: U) -> Chain { + fn chain(self, other: U) -> Chain where + U: Iterator::Item>, + { Chain{a: self, b: other, flag: false} } @@ -148,7 +152,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn zip>(self, other: U) -> Zip { + fn zip(self, other: U) -> Zip where + U: Iterator, + { Zip{a: self, b: other} } @@ -166,7 +172,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn map B>(self, f: F) -> Map { + fn map(self, f: F) -> Map< ::Item, B, Self, F> where + F: FnMut(::Item) -> B, + { Map{iter: self, f: f} } @@ -184,7 +192,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn filter

(self, predicate: P) -> Filter where P: FnMut(&A) -> bool { + fn filter

(self, predicate: P) -> Filter< ::Item, Self, P> where + P: FnMut(&::Item) -> bool, + { Filter{iter: self, predicate: predicate} } @@ -202,7 +212,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn filter_map(self, f: F) -> FilterMap where F: FnMut(A) -> Option { + fn filter_map(self, f: F) -> FilterMap< ::Item, B, Self, F> where + F: FnMut(::Item) -> Option, + { FilterMap { iter: self, f: f } } @@ -244,7 +256,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn peekable(self) -> Peekable { + fn peekable(self) -> Peekable< ::Item, Self> { Peekable{iter: self, peeked: None} } @@ -264,7 +276,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn skip_while

(self, predicate: P) -> SkipWhile where P: FnMut(&A) -> bool { + fn skip_while

(self, predicate: P) -> SkipWhile< ::Item, Self, P> where + P: FnMut(&::Item) -> bool, + { SkipWhile{iter: self, flag: false, predicate: predicate} } @@ -283,7 +297,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, may want to require peek"] - fn take_while

(self, predicate: P) -> TakeWhile where P: FnMut(&A) -> bool { + fn take_while

(self, predicate: P) -> TakeWhile< ::Item, Self, P> where + P: FnMut(&::Item) -> bool, + { TakeWhile{iter: self, flag: false, predicate: predicate} } @@ -346,8 +362,12 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn scan(self, initial_state: St, f: F) -> Scan where - F: FnMut(&mut St, A) -> Option, + fn scan( + self, + initial_state: St, + f: F, + ) -> Scan< ::Item, B, Self, St, F> where + F: FnMut(&mut St, ::Item) -> Option, { Scan{iter: self, f: f, state: initial_state} } @@ -372,9 +392,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn flat_map(self, f: F) -> FlatMap where - U: Iterator, - F: FnMut(A) -> U, + fn flat_map(self, f: F) -> FlatMap< ::Item, B, Self, U, F> where + U: Iterator, + F: FnMut(::Item) -> U, { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -386,7 +406,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Example /// /// ```rust - /// fn process>(it: U) -> int { + /// fn process>(it: U) -> int { /// let mut it = it.fuse(); /// let mut sum = 0; /// for x in it { @@ -432,7 +452,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn inspect(self, f: F) -> Inspect where F: FnMut(&A) { + fn inspect(self, f: F) -> Inspect< ::Item, Self, F> where + F: FnMut(&::Item), + { Inspect{iter: self, f: f} } @@ -468,7 +490,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for general conversion traits, just changed to take self by value"] - fn collect>(self) -> B { + fn collect::Item>>(self) -> B { FromIterator::from_iter(self) } @@ -485,7 +507,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[unstable = "recently added as part of collections reform"] fn partition(mut self, mut f: F) -> (B, B) where - B: Default + Extend, F: FnMut(&A) -> bool + B: Default + Extend< ::Item>, + F: FnMut(&::Item) -> bool { let mut left: B = Default::default(); let mut right: B = Default::default(); @@ -514,7 +537,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable] - fn nth(&mut self, mut n: uint) -> Option { + fn nth(&mut self, mut n: uint) -> Option< ::Item> { for x in *self { if n == 0 { return Some(x) } n -= 1; @@ -533,7 +556,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "just changed to take self by value"] - fn last(mut self) -> Option { + fn last(mut self) -> Option< ::Item> { let mut last = None; for x in self { last = Some(x); } last @@ -550,7 +573,9 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn fold(mut self, init: B, mut f: F) -> B where F: FnMut(B, A) -> B { + fn fold(mut self, init: B, mut f: F) -> B where + F: FnMut(B, ::Item) -> B, + { let mut accum = init; for x in self { accum = f(accum, x); @@ -584,7 +609,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn all(mut self, mut f: F) -> bool where F: FnMut(A) -> bool { + fn all(mut self, mut f: F) -> bool where F: FnMut(::Item) -> bool { for x in self { if !f(x) { return false; } } true } @@ -602,7 +627,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures"] - fn any(&mut self, mut f: F) -> bool where F: FnMut(A) -> bool { + fn any(&mut self, mut f: F) -> bool where F: FnMut(::Item) -> bool { for x in *self { if f(x) { return true; } } false } @@ -612,7 +637,9 @@ pub trait IteratorExt: Iterator + Sized { /// Does not consume the iterator past the first found element. #[inline] #[unstable = "waiting for unboxed closures"] - fn find

(&mut self, mut predicate: P) -> Option where P: FnMut(&A) -> bool { + fn find

(&mut self, mut predicate: P) -> Option< ::Item> where + P: FnMut(&::Item) -> bool, + { for x in *self { if predicate(&x) { return Some(x) } } @@ -622,7 +649,9 @@ pub trait IteratorExt: Iterator + Sized { /// Return the index of the first element satisfying the specified predicate #[inline] #[unstable = "waiting for unboxed closures"] - fn position

(&mut self, mut predicate: P) -> Option where P: FnMut(A) -> bool { + fn position

(&mut self, mut predicate: P) -> Option where + P: FnMut(::Item) -> bool, + { let mut i = 0; for x in *self { if predicate(x) { @@ -646,8 +675,10 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn max_by(self, mut f: F) -> Option where F: FnMut(&A) -> B { - self.fold(None, |max: Option<(A, B)>, x| { + fn max_by(self, mut f: F) -> Option< ::Item> where + F: FnMut(&::Item) -> B, + { + self.fold(None, |max: Option<(::Item, B)>, x| { let x_val = f(&x); match max { None => Some((x, x_val)), @@ -673,8 +704,10 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[unstable = "waiting for unboxed closures, just changed to take self by value"] - fn min_by(self, mut f: F) -> Option where F: FnMut(&A) -> B { - self.fold(None, |min: Option<(A, B)>, x| { + fn min_by(self, mut f: F) -> Option< ::Item> where + F: FnMut(&::Item) -> B, + { + self.fold(None, |min: Option<(::Item, B)>, x| { let x_val = f(&x); match min { None => Some((x, x_val)), @@ -689,11 +722,11 @@ pub trait IteratorExt: Iterator + Sized { } #[unstable = "trait is unstable"] -impl IteratorExt for I where I: Iterator {} +impl IteratorExt for I where I: Iterator {} /// Extention trait for iterators of pairs. #[unstable = "newly added trait, likely to be merged with IteratorExt"] -pub trait IteratorPairExt: Iterator<(A, B)> + Sized { +pub trait IteratorPairExt: Iterator + Sized { /// Converts an iterator of pairs into a pair of containers. /// /// Loops through the entire iterator, collecting the first component of @@ -702,7 +735,9 @@ pub trait IteratorPairExt: Iterator<(A, B)> + Sized { FromA: Default + Extend, FromB: Default + Extend { struct SizeHint(uint, Option); - impl Iterator for SizeHint { + impl Iterator for SizeHint { + type Item = A; + fn next(&mut self) -> Option { None } fn size_hint(&self) -> (uint, Option) { (self.0, self.1) @@ -725,21 +760,21 @@ pub trait IteratorPairExt: Iterator<(A, B)> + Sized { } } -impl IteratorPairExt for I where I: Iterator<(A, B)> {} +impl IteratorPairExt for I where I: Iterator {} /// A range iterator able to yield elements from both ends /// /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust /// elements from the *same* range, and do not work independently of each other. #[unstable = "recently split into two traits"] -pub trait DoubleEndedIterator: Iterator { +pub trait DoubleEndedIterator: Iterator { /// Yield an element from the end of the range, returning `None` if the range is empty. - fn next_back(&mut self) -> Option; + fn next_back(&mut self) -> Option< ::Item>; } /// Extension methods for double-ended iterators. #[unstable = "new extension trait convention"] -pub trait DoubleEndedIteratorExt: DoubleEndedIterator + Sized { +pub trait DoubleEndedIteratorExt: DoubleEndedIterator + Sized { /// Change the direction of the iterator /// /// The flipped iterator swaps the ends on an iterator that can already @@ -760,7 +795,7 @@ pub trait DoubleEndedIteratorExt: DoubleEndedIterator + Sized { } #[unstable = "trait is unstable"] -impl DoubleEndedIteratorExt for I where I: DoubleEndedIterator {} +impl DoubleEndedIteratorExt for I where I: DoubleEndedIterator {} /// A double-ended iterator yielding mutable references #[experimental = "not widely used"] @@ -771,7 +806,9 @@ pub trait MutableDoubleEndedIterator { } #[experimental = "trait is experimental"] -impl<'a, A:'a, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for T { +impl<'a, T:'a, I> MutableDoubleEndedIterator for I where + I: DoubleEndedIterator + Iterator, +{ // FIXME: #5898: should be called `reverse` /// Use an iterator to reverse a container in-place fn reverse_(&mut self) { @@ -792,13 +829,13 @@ impl<'a, A:'a, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for /// reduces the indexable range accordingly. That is, `it.idx(1)` will become `it.idx(0)` /// after `it.next()` is called. #[experimental = "not widely used, may be better decomposed into Index and ExactSizeIterator"] -pub trait RandomAccessIterator: Iterator { +pub trait RandomAccessIterator: Iterator { /// Return the number of indexable elements. At most `std::uint::MAX` /// elements are indexable, even if the iterator represents a longer range. fn indexable(&self) -> uint; /// Return an element at an index, or `None` if the index is out of bounds - fn idx(&mut self, index: uint) -> Option; + fn idx(&mut self, index: uint) -> Option< ::Item>; } /// An iterator that knows its exact length @@ -809,12 +846,14 @@ pub trait RandomAccessIterator: Iterator { /// `Iterator::size_hint` *must* return the exact size of the iterator. /// Note that the size must fit in `uint`. #[unstable = "could move DoubleEndedIterator bound onto rposition with method-level where clauses"] -pub trait ExactSizeIterator : DoubleEndedIterator { +pub trait ExactSizeIterator: DoubleEndedIterator { /// Return the index of the last element satisfying the specified predicate /// /// If no element matches, None is returned. #[inline] - fn rposition

(&mut self, mut predicate: P) -> Option where P: FnMut(A) -> bool { + fn rposition

(&mut self, mut predicate: P) -> Option where + P: FnMut(::Item) -> bool, + { let len = self.len(); for i in range(0, len).rev() { if predicate(self.next_back().expect("rposition: incorrect ExactSizeIterator")) { @@ -840,22 +879,21 @@ pub trait ExactSizeIterator : DoubleEndedIterator { // All adaptors that preserve the size of the wrapped iterator are fine // Adaptors that may overflow in `size_hint` are not, i.e. `Chain`. #[unstable = "trait is unstable"] -impl> ExactSizeIterator<(uint, A)> for Enumerate {} +impl ExactSizeIterator for Enumerate where I: ExactSizeIterator {} #[unstable = "trait is unstable"] -impl ExactSizeIterator for Inspect where - I: ExactSizeIterator, +impl ExactSizeIterator for Inspect where + I: ExactSizeIterator + Iterator, F: FnMut(&A), {} #[unstable = "trait is unstable"] -impl> ExactSizeIterator for Rev {} +impl ExactSizeIterator for Rev where I: ExactSizeIterator {} #[unstable = "trait is unstable"] -impl ExactSizeIterator for Map where - I: ExactSizeIterator, +impl ExactSizeIterator for Map where + I: ExactSizeIterator + Iterator, F: FnMut(A) -> B, {} #[unstable = "trait is unstable"] -impl ExactSizeIterator<(A, B)> for Zip - where T: ExactSizeIterator, U: ExactSizeIterator {} +impl ExactSizeIterator for Zip where A: ExactSizeIterator, B: ExactSizeIterator {} /// An double-ended iterator with the direction inverted #[deriving(Clone)] @@ -866,26 +904,27 @@ pub struct Rev { } #[unstable = "trait is unstable"] -impl> Iterator for Rev { +impl Iterator for Rev where I: DoubleEndedIterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { self.iter.next_back() } + fn next(&mut self) -> Option< ::Item> { self.iter.next_back() } #[inline] fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[unstable = "trait is unstable"] -impl> DoubleEndedIterator for Rev { +impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option { self.iter.next() } + fn next_back(&mut self) -> Option< ::Item> { self.iter.next() } } #[experimental = "trait is experimental"] -impl + RandomAccessIterator> RandomAccessIterator - for Rev { +impl RandomAccessIterator for Rev where I: DoubleEndedIterator + RandomAccessIterator { #[inline] fn indexable(&self) -> uint { self.iter.indexable() } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { let amt = self.indexable(); self.iter.idx(amt - index - 1) } @@ -894,22 +933,24 @@ impl + RandomAccessIterator> RandomAccessIterato /// A mutable reference to an iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct ByRef<'a, T:'a> { - iter: &'a mut T +pub struct ByRef<'a, I:'a> { + iter: &'a mut I, } #[unstable = "trait is unstable"] -impl<'a, A, T: Iterator+'a> Iterator for ByRef<'a, T> { +impl<'a, I> Iterator for ByRef<'a, I> where I: 'a + Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { self.iter.next() } + fn next(&mut self) -> Option< ::Item> { self.iter.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } #[unstable = "trait is unstable"] -impl<'a, A, T: DoubleEndedIterator+'a> DoubleEndedIterator for ByRef<'a, T> { +impl<'a, I> DoubleEndedIterator for ByRef<'a, I> where I: 'a + DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option { self.iter.next_back() } + fn next_back(&mut self) -> Option< ::Item> { self.iter.next_back() } } /// A trait for iterators over elements which can be added together @@ -932,7 +973,7 @@ pub trait AdditiveIterator { macro_rules! impl_additive { ($A:ty, $init:expr) => { #[experimental = "trait is experimental"] - impl> AdditiveIterator<$A> for T { + impl> AdditiveIterator<$A> for T { #[inline] fn sum(self) -> $A { self.fold($init, |acc, x| acc + x) @@ -976,7 +1017,7 @@ pub trait MultiplicativeIterator { macro_rules! impl_multiplicative { ($A:ty, $init:expr) => { #[experimental = "trait is experimental"] - impl> MultiplicativeIterator<$A> for T { + impl> MultiplicativeIterator<$A> for T { #[inline] fn product(self) -> $A { self.fold($init, |acc, x| acc * x) @@ -1057,9 +1098,9 @@ pub trait IteratorOrdExt { } #[unstable = "trait is unstable"] -impl> IteratorOrdExt for T { +impl IteratorOrdExt for I where I: Iterator, T: Ord { #[inline] - fn max(self) -> Option { + fn max(self) -> Option { self.fold(None, |max, x| { match max { None => Some(x), @@ -1069,7 +1110,7 @@ impl> IteratorOrdExt for T { } #[inline] - fn min(self) -> Option { + fn min(self) -> Option { self.fold(None, |min, x| { match min { None => Some(x), @@ -1078,7 +1119,7 @@ impl> IteratorOrdExt for T { }) } - fn min_max(mut self) -> MinMaxResult { + fn min_max(mut self) -> MinMaxResult { let (mut min, mut max) = match self.next() { None => return NoElements, Some(x) => { @@ -1175,7 +1216,11 @@ pub trait IteratorCloneExt { } #[unstable = "trait is unstable"] -impl, I: Iterator> IteratorCloneExt for I { +impl IteratorCloneExt for I where + T: Clone, + D: Deref, + I: Iterator, +{ fn cloned(self) -> Cloned { Cloned { it: self } } @@ -1186,8 +1231,14 @@ pub struct Cloned { it: I, } -impl, I: Iterator> Iterator for Cloned { - fn next(&mut self) -> Option { +impl Iterator for Cloned where + T: Clone, + D: Deref, + I: Iterator, +{ + type Item = T; + + fn next(&mut self) -> Option { self.it.next().cloned() } @@ -1196,15 +1247,22 @@ impl, I: Iterator> Iterator for Cloned { } } -impl, I: DoubleEndedIterator> - DoubleEndedIterator for Cloned { - fn next_back(&mut self) -> Option { +impl DoubleEndedIterator for Cloned where + T: Clone, + D: Deref, + I: DoubleEndedIterator + Iterator, +{ + fn next_back(&mut self) -> Option { self.it.next_back().cloned() } } #[unstable = "trait is unstable"] -impl, I: ExactSizeIterator> ExactSizeIterator for Cloned {} +impl ExactSizeIterator for Cloned where + T: Clone, + D: Deref, + I: ExactSizeIterator + Iterator, +{} #[unstable = "recently renamed for extension trait conventions"] /// An extension trait for cloneable iterators. @@ -1225,7 +1283,7 @@ pub trait CloneIteratorExt { fn cycle(self) -> Cycle; } -impl CloneIteratorExt for I where I: Iterator + Clone { +impl CloneIteratorExt for I where I: Iterator + Clone { #[inline] fn cycle(self) -> Cycle { Cycle{orig: self.clone(), iter: self} @@ -1236,14 +1294,16 @@ impl CloneIteratorExt for I where I: Iterator + Clone { #[deriving(Clone, Copy)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Cycle { - orig: T, - iter: T, +pub struct Cycle { + orig: I, + iter: I, } -impl> Iterator for Cycle { +impl Iterator for Cycle where I: Clone + Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { match self.iter.next() { None => { self.iter = self.orig.clone(); self.iter.next() } y => y @@ -1262,7 +1322,9 @@ impl> Iterator for Cycle { } #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Cycle { +impl RandomAccessIterator for Cycle where + I: Clone + RandomAccessIterator, +{ #[inline] fn indexable(&self) -> uint { if self.orig.indexable() > 0 { @@ -1273,7 +1335,7 @@ impl> RandomAccessIterator for Cycle } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { let liter = self.iter.indexable(); let lorig = self.orig.indexable(); if lorig == 0 { @@ -1290,16 +1352,18 @@ impl> RandomAccessIterator for Cycle #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Chain { - a: T, - b: U, +pub struct Chain { + a: A, + b: B, flag: bool, } #[unstable = "trait is unstable"] -impl, U: Iterator> Iterator for Chain { +impl Iterator for Chain where A: Iterator, B: Iterator { + type Item = T; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.flag { self.b.next() } else { @@ -1329,10 +1393,12 @@ impl, U: Iterator> Iterator for Chain { } #[unstable = "trait is unstable"] -impl, U: DoubleEndedIterator> DoubleEndedIterator -for Chain { +impl DoubleEndedIterator for Chain where + A: DoubleEndedIterator + Iterator, + B: DoubleEndedIterator + Iterator, +{ #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { match self.b.next_back() { Some(x) => Some(x), None => self.a.next_back() @@ -1341,8 +1407,10 @@ for Chain { } #[experimental = "trait is experimental"] -impl, U: RandomAccessIterator> RandomAccessIterator -for Chain { +impl RandomAccessIterator for Chain where + A: RandomAccessIterator + Iterator, + B: RandomAccessIterator + Iterator, +{ #[inline] fn indexable(&self) -> uint { let (a, b) = (self.a.indexable(), self.b.indexable()); @@ -1350,7 +1418,7 @@ for Chain { } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option { let len = self.a.indexable(); if index < len { self.a.idx(index) @@ -1364,15 +1432,20 @@ for Chain { #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Zip { - a: T, - b: U +pub struct Zip { + a: A, + b: B } #[unstable = "trait is unstable"] -impl, U: Iterator> Iterator<(A, B)> for Zip { +impl Iterator for Zip where + A: Iterator, + B: Iterator, +{ + type Item = (T, U); + #[inline] - fn next(&mut self) -> Option<(A, B)> { + fn next(&mut self) -> Option<(T, U)> { match self.a.next() { None => None, Some(x) => match self.b.next() { @@ -1401,10 +1474,12 @@ impl, U: Iterator> Iterator<(A, B)> for Zip { } #[unstable = "trait is unstable"] -impl, U: ExactSizeIterator> DoubleEndedIterator<(A, B)> -for Zip { +impl DoubleEndedIterator for Zip where + A: ExactSizeIterator + Iterator, + B: ExactSizeIterator + Iterator, +{ #[inline] - fn next_back(&mut self) -> Option<(A, B)> { + fn next_back(&mut self) -> Option<(T, U)> { let a_sz = self.a.len(); let b_sz = self.b.len(); if a_sz != b_sz { @@ -1424,15 +1499,17 @@ for Zip { } #[experimental = "trait is experimental"] -impl, U: RandomAccessIterator> -RandomAccessIterator<(A, B)> for Zip { +impl RandomAccessIterator for Zip where + A: RandomAccessIterator + Iterator, + B: RandomAccessIterator + Iterator, +{ #[inline] fn indexable(&self) -> uint { cmp::min(self.a.indexable(), self.b.indexable()) } #[inline] - fn idx(&mut self, index: uint) -> Option<(A, B)> { + fn idx(&mut self, index: uint) -> Option<(T, U)> { match self.a.idx(index) { None => None, Some(x) => match self.b.idx(index) { @@ -1446,7 +1523,7 @@ RandomAccessIterator<(A, B)> for Zip { /// An iterator that maps the values of `iter` with `f` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Map, F: FnMut(A) -> B> { +pub struct Map, F: FnMut(A) -> B> { iter: I, f: F, } @@ -1454,7 +1531,7 @@ pub struct Map, F: FnMut(A) -> B> { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Map where - I: Clone + Iterator, + I: Clone + Iterator, F: Clone + FnMut(A) -> B, { fn clone(&self) -> Map { @@ -1465,7 +1542,7 @@ impl Clone for Map where } } -impl Map where I: Iterator, F: FnMut(A) -> B { +impl Map where I: Iterator, F: FnMut(A) -> B { #[inline] fn do_map(&mut self, elt: Option) -> Option { match elt { @@ -1476,7 +1553,9 @@ impl Map where I: Iterator, F: FnMut(A) -> B { } #[unstable = "trait is unstable"] -impl Iterator for Map where I: Iterator, F: FnMut(A) -> B { +impl Iterator for Map where I: Iterator, F: FnMut(A) -> B { + type Item = B; + #[inline] fn next(&mut self) -> Option { let next = self.iter.next(); @@ -1490,8 +1569,8 @@ impl Iterator for Map where I: Iterator, F: FnMut( } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Map where - I: DoubleEndedIterator, +impl DoubleEndedIterator for Map where + I: DoubleEndedIterator + Iterator, F: FnMut(A) -> B, { #[inline] @@ -1502,8 +1581,8 @@ impl DoubleEndedIterator for Map where } #[experimental = "trait is experimental"] -impl RandomAccessIterator for Map where - I: RandomAccessIterator, +impl RandomAccessIterator for Map where + I: RandomAccessIterator + Iterator, F: FnMut(A) -> B, { #[inline] @@ -1521,7 +1600,7 @@ impl RandomAccessIterator for Map where /// An iterator that filters the elements of `iter` with `predicate` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { +pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { iter: I, predicate: P, } @@ -1529,7 +1608,7 @@ pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Filter where - I: Clone + Iterator, + I: Clone + Iterator, P: Clone + FnMut(&A) -> bool, { fn clone(&self) -> Filter { @@ -1541,7 +1620,9 @@ impl Clone for Filter where } #[unstable = "trait is unstable"] -impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { +impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { + type Item = A; + #[inline] fn next(&mut self) -> Option { for x in self.iter { @@ -1562,8 +1643,8 @@ impl Iterator for Filter where I: Iterator, P: FnMut(&A) } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Filter where - I: DoubleEndedIterator, +impl DoubleEndedIterator for Filter where + I: DoubleEndedIterator + Iterator, P: FnMut(&A) -> bool, { #[inline] @@ -1580,7 +1661,7 @@ impl DoubleEndedIterator for Filter where /// An iterator that uses `f` to both filter and map elements from `iter` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option { +pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option { iter: I, f: F, } @@ -1588,7 +1669,7 @@ pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for FilterMap where - I: Clone + Iterator, + I: Clone + Iterator, F: Clone + FnMut(A) -> Option, { fn clone(&self) -> FilterMap { @@ -1600,10 +1681,12 @@ impl Clone for FilterMap where } #[unstable = "trait is unstable"] -impl Iterator for FilterMap where - I: Iterator, +impl Iterator for FilterMap where + I: Iterator, F: FnMut(A) -> Option, { + type Item = B; + #[inline] fn next(&mut self) -> Option { for x in self.iter { @@ -1623,8 +1706,8 @@ impl Iterator for FilterMap where } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for FilterMap where - I: DoubleEndedIterator, +impl DoubleEndedIterator for FilterMap where + I: DoubleEndedIterator + Iterator, F: FnMut(A) -> Option, { #[inline] @@ -1643,15 +1726,17 @@ impl DoubleEndedIterator for FilterMap where #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Enumerate { - iter: T, +pub struct Enumerate { + iter: I, count: uint } #[unstable = "trait is unstable"] -impl> Iterator<(uint, A)> for Enumerate { +impl Iterator for Enumerate where I: Iterator { + type Item = (uint, ::Item); + #[inline] - fn next(&mut self) -> Option<(uint, A)> { + fn next(&mut self) -> Option<(uint, ::Item)> { match self.iter.next() { Some(a) => { let ret = Some((self.count, a)); @@ -1669,9 +1754,9 @@ impl> Iterator<(uint, A)> for Enumerate { } #[unstable = "trait is unstable"] -impl> DoubleEndedIterator<(uint, A)> for Enumerate { +impl DoubleEndedIterator for Enumerate where I: ExactSizeIterator { #[inline] - fn next_back(&mut self) -> Option<(uint, A)> { + fn next_back(&mut self) -> Option<(uint, ::Item)> { match self.iter.next_back() { Some(a) => { let len = self.iter.len(); @@ -1683,14 +1768,14 @@ impl> DoubleEndedIterator<(uint, A)> for Enumerate } #[experimental = "trait is experimental"] -impl> RandomAccessIterator<(uint, A)> for Enumerate { +impl RandomAccessIterator for Enumerate where I: RandomAccessIterator { #[inline] fn indexable(&self) -> uint { self.iter.indexable() } #[inline] - fn idx(&mut self, index: uint) -> Option<(uint, A)> { + fn idx(&mut self, index: uint) -> Option<(uint, ::Item)> { match self.iter.idx(index) { Some(a) => Some((self.count + index, a)), _ => None, @@ -1702,14 +1787,16 @@ impl> RandomAccessIterator<(uint, A)> for Enumerat #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] #[deriving(Copy)] -pub struct Peekable { - iter: T, - peeked: Option, +pub struct Peekable where I: Iterator { + iter: I, + peeked: Option, } -impl> Iterator for Peekable { +impl Iterator for Peekable where I: Iterator { + type Item = T; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.peeked.is_some() { self.peeked.take() } else { self.iter.next() } } @@ -1731,11 +1818,11 @@ impl> Iterator for Peekable { } #[stable] -impl<'a, A, T: Iterator> Peekable { +impl Peekable where I: Iterator { /// Return a reference to the next element of the iterator with out advancing it, /// or None if the iterator is exhausted. #[inline] - pub fn peek(&'a mut self) -> Option<&'a A> { + pub fn peek(&mut self) -> Option<&T> { if self.peeked.is_none() { self.peeked = self.iter.next(); } @@ -1755,7 +1842,7 @@ impl<'a, A, T: Iterator> Peekable { /// An iterator that rejects elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { +pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { iter: I, flag: bool, predicate: P, @@ -1764,7 +1851,7 @@ pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for SkipWhile where - I: Clone + Iterator, + I: Clone + Iterator, P: Clone + FnMut(&A) -> bool, { fn clone(&self) -> SkipWhile { @@ -1777,7 +1864,9 @@ impl Clone for SkipWhile where } #[unstable = "trait is unstable"] -impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { +impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { + type Item = A; + #[inline] fn next(&mut self) -> Option { for x in self.iter { @@ -1799,7 +1888,7 @@ impl Iterator for SkipWhile where I: Iterator, P: FnMut( /// An iterator that only accepts elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { +pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { iter: I, flag: bool, predicate: P, @@ -1808,7 +1897,7 @@ pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for TakeWhile where - I: Clone + Iterator, + I: Clone + Iterator, P: Clone + FnMut(&A) -> bool, { fn clone(&self) -> TakeWhile { @@ -1821,7 +1910,9 @@ impl Clone for TakeWhile where } #[unstable = "trait is unstable"] -impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { +impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { + type Item = A; + #[inline] fn next(&mut self) -> Option { if self.flag { @@ -1852,15 +1943,17 @@ impl Iterator for TakeWhile where I: Iterator, P: FnMut( #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Skip { - iter: T, +pub struct Skip { + iter: I, n: uint } #[unstable = "trait is unstable"] -impl> Iterator for Skip { +impl Iterator for Skip where I: Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { let mut next = self.iter.next(); if self.n == 0 { next @@ -1900,14 +1993,14 @@ impl> Iterator for Skip { } #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Skip { +impl RandomAccessIterator for Skip where I: RandomAccessIterator{ #[inline] fn indexable(&self) -> uint { self.iter.indexable().saturating_sub(self.n) } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { if index >= self.indexable() { None } else { @@ -1920,15 +2013,17 @@ impl> RandomAccessIterator for Skip { #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Take { - iter: T, +pub struct Take { + iter: I, n: uint } #[unstable = "trait is unstable"] -impl> Iterator for Take { +impl Iterator for Take where I: Iterator{ + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { if self.n != 0 { self.n -= 1; self.iter.next() @@ -1953,14 +2048,14 @@ impl> Iterator for Take { } #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Take { +impl RandomAccessIterator for Take where I: RandomAccessIterator{ #[inline] fn indexable(&self) -> uint { cmp::min(self.iter.indexable(), self.n) } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { if index >= self.n { None } else { @@ -1973,7 +2068,7 @@ impl> RandomAccessIterator for Take { /// An iterator to maintain state while iterating another iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[unstable = "waiting for unboxed closures"] -pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Option { +pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Option { iter: I, f: F, @@ -1984,7 +2079,7 @@ pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Op // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Scan where - I: Clone + Iterator, + I: Clone + Iterator, St: Clone, F: Clone + FnMut(&mut St, A) -> Option, { @@ -1998,10 +2093,12 @@ impl Clone for Scan where } #[unstable = "trait is unstable"] -impl Iterator for Scan where - I: Iterator, +impl Iterator for Scan where + I: Iterator, F: FnMut(&mut St, A) -> Option, { + type Item = B; + #[inline] fn next(&mut self) -> Option { self.iter.next().and_then(|a| (self.f)(&mut self.state, a)) @@ -2019,7 +2116,11 @@ impl Iterator for Scan where /// #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[unstable = "waiting for unboxed closures"] -pub struct FlatMap where I: Iterator, U: Iterator, F: FnMut(A) -> U { +pub struct FlatMap where + I: Iterator, + U: Iterator, + F: FnMut(A) -> U, +{ iter: I, f: F, frontiter: Option, @@ -2029,8 +2130,8 @@ pub struct FlatMap where I: Iterator, U: Iterator, F: FnMut // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for FlatMap where - I: Clone + Iterator, - U: Clone + Iterator, + I: Clone + Iterator, + U: Clone + Iterator, F: Clone + FnMut(A) -> U, { fn clone(&self) -> FlatMap { @@ -2044,11 +2145,13 @@ impl Clone for FlatMap where } #[unstable = "trait is unstable"] -impl Iterator for FlatMap where - I: Iterator, - U: Iterator, +impl Iterator for FlatMap where + I: Iterator, + U: Iterator, F: FnMut(A) -> U, { + type Item = B; + #[inline] fn next(&mut self) -> Option { loop { @@ -2077,9 +2180,9 @@ impl Iterator for FlatMap where } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for FlatMap where - I: DoubleEndedIterator, - U: DoubleEndedIterator, +impl DoubleEndedIterator for FlatMap where + I: DoubleEndedIterator + Iterator, + U: DoubleEndedIterator + Iterator, F: FnMut(A) -> U, { #[inline] @@ -2104,15 +2207,17 @@ impl DoubleEndedIterator for FlatMap where #[deriving(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable] -pub struct Fuse { - iter: T, +pub struct Fuse { + iter: I, done: bool } #[unstable = "trait is unstable"] -impl> Iterator for Fuse { +impl Iterator for Fuse where I: Iterator { + type Item = ::Item; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option< ::Item> { if self.done { None } else { @@ -2137,9 +2242,9 @@ impl> Iterator for Fuse { } #[unstable = "trait is unstable"] -impl> DoubleEndedIterator for Fuse { +impl DoubleEndedIterator for Fuse where I: DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option< ::Item> { if self.done { None } else { @@ -2156,20 +2261,20 @@ impl> DoubleEndedIterator for Fuse { // Allow RandomAccessIterators to be fused without affecting random-access behavior #[experimental = "trait is experimental"] -impl> RandomAccessIterator for Fuse { +impl RandomAccessIterator for Fuse where I: RandomAccessIterator { #[inline] fn indexable(&self) -> uint { self.iter.indexable() } #[inline] - fn idx(&mut self, index: uint) -> Option { + fn idx(&mut self, index: uint) -> Option< ::Item> { self.iter.idx(index) } } #[experimental = "seems marginal"] -impl Fuse { +impl Fuse { /// Resets the fuse such that the next call to .next() or .next_back() will /// call the underlying iterator again even if it previously returned None. #[inline] @@ -2182,7 +2287,7 @@ impl Fuse { /// element before yielding it. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[unstable = "waiting for unboxed closures"] -pub struct Inspect where I: Iterator, F: FnMut(&A) { +pub struct Inspect where I: Iterator, F: FnMut(&A) { iter: I, f: F, } @@ -2190,7 +2295,7 @@ pub struct Inspect where I: Iterator, F: FnMut(&A) { // FIXME(#19839) Remove in favor of `#[deriving(Clone)]` #[stable] impl Clone for Inspect where - I: Clone + Iterator, + I: Clone + Iterator, F: Clone + FnMut(&A), { fn clone(&self) -> Inspect { @@ -2201,7 +2306,7 @@ impl Clone for Inspect where } } -impl Inspect where I: Iterator, F: FnMut(&A) { +impl Inspect where I: Iterator, F: FnMut(&A) { #[inline] fn do_inspect(&mut self, elt: Option) -> Option { match elt { @@ -2214,7 +2319,9 @@ impl Inspect where I: Iterator, F: FnMut(&A) { } #[unstable = "trait is unstable"] -impl Iterator for Inspect where I: Iterator, F: FnMut(&A) { +impl Iterator for Inspect where I: Iterator, F: FnMut(&A) { + type Item = A; + #[inline] fn next(&mut self) -> Option { let next = self.iter.next(); @@ -2228,8 +2335,8 @@ impl Iterator for Inspect where I: Iterator, F: FnMut(&A } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Inspect where - I: DoubleEndedIterator, +impl DoubleEndedIterator for Inspect where + I: DoubleEndedIterator + Iterator, F: FnMut(&A), { #[inline] @@ -2240,8 +2347,8 @@ impl DoubleEndedIterator for Inspect where } #[experimental = "trait is experimental"] -impl RandomAccessIterator for Inspect where - I: RandomAccessIterator, +impl RandomAccessIterator for Inspect where + I: RandomAccessIterator + Iterator, F: FnMut(&A), { #[inline] @@ -2323,7 +2430,9 @@ impl Unfold where F: FnMut(&mut St) -> Option { } #[experimental] -impl Iterator for Unfold where F: FnMut(&mut St) -> Option { +impl Iterator for Unfold where F: FnMut(&mut St) -> Option { + type Item = A; + #[inline] fn next(&mut self) -> Option { (self.f)(&mut self.state) @@ -2355,7 +2464,9 @@ pub fn count(start: A, step: A) -> Counter { } #[unstable = "trait is unstable"] -impl + Clone> Iterator for Counter { +impl + Clone> Iterator for Counter { + type Item = A; + #[inline] fn next(&mut self) -> Option { let result = self.state.clone(); @@ -2402,7 +2513,9 @@ pub fn range(start: A, stop: A) -> Range { // FIXME: #10414: Unfortunate type bound #[unstable = "trait is unstable"] -impl Iterator for Range { +impl Iterator for Range { + type Item = A; + #[inline] fn next(&mut self) -> Option { if self.state < self.stop { @@ -2450,7 +2563,7 @@ impl Iterator for Range { /// `Int` is required to ensure the range will be the same regardless of /// the direction it is consumed. #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Range { +impl DoubleEndedIterator for Range { #[inline] fn next_back(&mut self) -> Option { if self.stop > self.state { @@ -2481,7 +2594,9 @@ pub fn range_inclusive(start: A, stop: A) -> RangeInclusive { } #[unstable = "trait is unstable"] -impl Iterator for RangeInclusive { +impl Iterator for RangeInclusive { + type Item = A; + #[inline] fn next(&mut self) -> Option { match self.range.next() { @@ -2514,7 +2629,7 @@ impl Iterator for RangeInclusive { } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for RangeInclusive { +impl DoubleEndedIterator for RangeInclusive { #[inline] fn next_back(&mut self) -> Option { if self.range.stop > self.range.state { @@ -2549,7 +2664,9 @@ pub fn range_step(start: A, stop: A, step: A) -> RangeStep { } #[unstable = "trait is unstable"] -impl Iterator for RangeStep { +impl Iterator for RangeStep { + type Item = A; + #[inline] fn next(&mut self) -> Option { if (self.rev && self.state > self.stop) || (!self.rev && self.state < self.stop) { @@ -2591,7 +2708,9 @@ pub fn range_step_inclusive(start: A, stop: A, step: A) -> RangeStepIncl } #[unstable = "trait is unstable"] -impl Iterator for RangeStepInclusive { +impl Iterator for RangeStepInclusive { + type Item = A; + #[inline] fn next(&mut self) -> Option { if !self.done && ((self.rev && self.state >= self.stop) || @@ -2683,7 +2802,9 @@ impl Repeat { } #[unstable = "trait is unstable"] -impl Iterator for Repeat { +impl Iterator for Repeat { + type Item = A; + #[inline] fn next(&mut self) -> Option { self.idx(0) } #[inline] @@ -2691,13 +2812,13 @@ impl Iterator for Repeat { } #[unstable = "trait is unstable"] -impl DoubleEndedIterator for Repeat { +impl DoubleEndedIterator for Repeat { #[inline] fn next_back(&mut self) -> Option { self.idx(0) } } #[experimental = "trait is experimental"] -impl RandomAccessIterator for Repeat { +impl RandomAccessIterator for Repeat { #[inline] fn indexable(&self) -> uint { uint::MAX } #[inline] @@ -2766,7 +2887,11 @@ pub mod order { use super::Iterator; /// Compare `a` and `b` for equality using `Eq` - pub fn equals, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn equals(mut a: T, mut b: S) -> bool where + A: Eq, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return true, @@ -2777,7 +2902,11 @@ pub mod order { } /// Order `a` and `b` lexicographically using `Ord` - pub fn cmp, S: Iterator>(mut a: T, mut b: S) -> cmp::Ordering { + pub fn cmp(mut a: T, mut b: S) -> cmp::Ordering where + A: Ord, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return Equal, @@ -2792,8 +2921,11 @@ pub mod order { } /// Order `a` and `b` lexicographically using `PartialOrd` - pub fn partial_cmp, S: Iterator>(mut a: T, mut b: S) - -> Option { + pub fn partial_cmp(mut a: T, mut b: S) -> Option where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return Some(Equal), @@ -2810,8 +2942,8 @@ pub mod order { /// Compare `a` and `b` for equality (Using partial equality, `PartialEq`) pub fn eq(mut a: L, mut b: R) -> bool where A: PartialEq, - L: Iterator, - R: Iterator, + L: Iterator, + R: Iterator, { loop { match (a.next(), b.next()) { @@ -2825,8 +2957,8 @@ pub mod order { /// Compare `a` and `b` for nonequality (Using partial equality, `PartialEq`) pub fn ne(mut a: L, mut b: R) -> bool where A: PartialEq, - L: Iterator, - R: Iterator, + L: Iterator, + R: Iterator, { loop { match (a.next(), b.next()) { @@ -2838,7 +2970,11 @@ pub mod order { } /// Return `a` < `b` lexicographically (Using partial order, `PartialOrd`) - pub fn lt, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn lt(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return false, @@ -2850,7 +2986,11 @@ pub mod order { } /// Return `a` <= `b` lexicographically (Using partial order, `PartialOrd`) - pub fn le, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn le(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return true, @@ -2862,7 +3002,11 @@ pub mod order { } /// Return `a` > `b` lexicographically (Using partial order, `PartialOrd`) - pub fn gt, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn gt(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return false, @@ -2874,7 +3018,11 @@ pub mod order { } /// Return `a` >= `b` lexicographically (Using partial order, `PartialOrd`) - pub fn ge, S: Iterator>(mut a: T, mut b: S) -> bool { + pub fn ge(mut a: T, mut b: S) -> bool where + A: PartialOrd, + T: Iterator, + S: Iterator, + { loop { match (a.next(), b.next()) { (None, None) => return true, diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index b51d4d91c2f..c5441359ad0 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -789,7 +789,9 @@ pub struct Range { // FIXME(#19391) needs a snapshot //impl> Iterator for Range { -impl Iterator for Range { +impl Iterator for Range { + type Item = Idx; + #[inline] fn next(&mut self) -> Option { if self.start < self.end { @@ -811,7 +813,7 @@ impl Iterator for Range { } } -impl DoubleEndedIterator for Range { +impl DoubleEndedIterator for Range { #[inline] fn next_back(&mut self) -> Option { if self.start < self.end { @@ -823,7 +825,7 @@ impl DoubleEndedIterator for Range { } } -impl ExactSizeIterator for Range {} +impl ExactSizeIterator for Range {} /// A range which is only bounded below. #[deriving(Copy)] @@ -833,7 +835,9 @@ pub struct RangeFrom { pub start: Idx, } -impl Iterator for RangeFrom { +impl Iterator for RangeFrom { + type Item = Idx; + #[inline] fn next(&mut self) -> Option { // Deliberately overflow so we loop forever. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b9749f57d58..92209b937d9 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -777,7 +777,9 @@ struct Item { opt: Option } -impl Iterator for Item { +impl Iterator for Item { + type Item = A; + #[inline] fn next(&mut self) -> Option { self.opt.take() @@ -792,32 +794,34 @@ impl Iterator for Item { } } -impl DoubleEndedIterator for Item { +impl DoubleEndedIterator for Item { #[inline] fn next_back(&mut self) -> Option { self.opt.take() } } -impl ExactSizeIterator for Item {} +impl ExactSizeIterator for Item {} /// An iterator over a reference of the contained item in an Option. #[stable] pub struct Iter<'a, A: 'a> { inner: Item<&'a A> } -impl<'a, A> Iterator<&'a A> for Iter<'a, A> { +impl<'a, A> Iterator for Iter<'a, A> { + type Item = &'a A; + #[inline] fn next(&mut self) -> Option<&'a A> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> { +impl<'a, A> DoubleEndedIterator for Iter<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a A> { self.inner.next_back() } } -impl<'a, A> ExactSizeIterator<&'a A> for Iter<'a, A> {} +impl<'a, A> ExactSizeIterator for Iter<'a, A> {} #[stable] impl<'a, A> Clone for Iter<'a, A> { @@ -830,37 +834,41 @@ impl<'a, A> Clone for Iter<'a, A> { #[stable] pub struct IterMut<'a, A: 'a> { inner: Item<&'a mut A> } -impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> { +impl<'a, A> Iterator for IterMut<'a, A> { + type Item = &'a mut A; + #[inline] fn next(&mut self) -> Option<&'a mut A> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> { +impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a mut A> { self.inner.next_back() } } -impl<'a, A> ExactSizeIterator<&'a mut A> for IterMut<'a, A> {} +impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} /// An iterator over the item contained inside an Option. #[stable] pub struct IntoIter { inner: Item } -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = A; + #[inline] fn next(&mut self) -> Option { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.next_back() } } -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} ///////////////////////////////////////////////////////////////////////////// // FromIterator @@ -887,7 +895,7 @@ impl> FromIterator> for Option { /// ``` #[inline] #[stable] - fn from_iter>>(iter: I) -> Option { + fn from_iter>>(iter: I) -> Option { // FIXME(#11084): This could be replaced with Iterator::scan when this // performance bug is closed. @@ -896,7 +904,9 @@ impl> FromIterator> for Option { found_none: bool, } - impl>> Iterator for Adapter { + impl>> Iterator for Adapter { + type Item = T; + #[inline] fn next(&mut self) -> Option { match self.iter.next() { diff --git a/src/libcore/result.rs b/src/libcore/result.rs index bd1c6dbcf1e..b0ee5672e06 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -807,7 +807,9 @@ impl AsSlice for Result { #[stable] pub struct Iter<'a, T: 'a> { inner: Option<&'a T> } -impl<'a, T> Iterator<&'a T> for Iter<'a, T> { +impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { self.inner.take() } #[inline] @@ -817,12 +819,12 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { +impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { self.inner.take() } } -impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +impl<'a, T> ExactSizeIterator for Iter<'a, T> {} impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { Iter { inner: self.inner } } @@ -832,7 +834,9 @@ impl<'a, T> Clone for Iter<'a, T> { #[stable] pub struct IterMut<'a, T: 'a> { inner: Option<&'a mut T> } -impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { +impl<'a, T> Iterator for IterMut<'a, T> { + type Item = &'a mut T; + #[inline] fn next(&mut self) -> Option<&'a mut T> { self.inner.take() } #[inline] @@ -842,18 +846,20 @@ impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> { +impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { self.inner.take() } } -impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} +impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// An iterator over the value in a `Ok` variant of a `Result`. #[stable] pub struct IntoIter { inner: Option } -impl Iterator for IntoIter { +impl Iterator for IntoIter { + type Item = T; + #[inline] fn next(&mut self) -> Option { self.inner.take() } #[inline] @@ -863,12 +869,12 @@ impl Iterator for IntoIter { } } -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.take() } } -impl ExactSizeIterator for IntoIter {} +impl ExactSizeIterator for IntoIter {} ///////////////////////////////////////////////////////////////////////////// // FromIterator @@ -894,7 +900,7 @@ impl> FromIterator> for Result { /// assert!(res == Ok(vec!(2u, 3u))); /// ``` #[inline] - fn from_iter>>(iter: I) -> Result { + fn from_iter>>(iter: I) -> Result { // FIXME(#11084): This could be replaced with Iterator::scan when this // performance bug is closed. @@ -903,7 +909,9 @@ impl> FromIterator> for Result { err: Option, } - impl>> Iterator for Adapter { + impl>> Iterator for Adapter { + type Item = T; + #[inline] fn next(&mut self) -> Option { match self.iter.next() { @@ -941,7 +949,7 @@ pub fn fold V, - Iter: Iterator>>( + Iter: Iterator>>( mut iterator: Iter, mut init: V, mut f: F) diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 07addf7a569..bc4e8d32887 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -647,7 +647,9 @@ impl<'a, T> Default for &'a [T] { macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { #[experimental = "needs review"] - impl<'a, T> Iterator<$elem> for $name<'a, T> { + impl<'a, T> Iterator for $name<'a, T> { + type Item = $elem; + #[inline] fn next(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks @@ -683,7 +685,7 @@ macro_rules! iterator { } #[experimental = "needs review"] - impl<'a, T> DoubleEndedIterator<$elem> for $name<'a, T> { + impl<'a, T> DoubleEndedIterator for $name<'a, T> { #[inline] fn next_back(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks @@ -766,7 +768,7 @@ impl<'a,T> Copy for Iter<'a,T> {} iterator!{struct Iter -> *const T, &'a T} #[experimental = "needs review"] -impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +impl<'a, T> ExactSizeIterator for Iter<'a, T> {} #[stable] impl<'a, T> Clone for Iter<'a, T> { @@ -774,7 +776,7 @@ impl<'a, T> Clone for Iter<'a, T> { } #[experimental = "needs review"] -impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> { +impl<'a, T> RandomAccessIterator for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { let (exact, _) = self.size_hint(); @@ -860,14 +862,14 @@ impl<'a, T> IterMut<'a, T> { iterator!{struct IterMut -> *mut T, &'a mut T} #[experimental = "needs review"] -impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} +impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// An internal abstraction over the splitting iterators, so that /// splitn, splitn_mut etc can be implemented once. -trait SplitIter: DoubleEndedIterator { +trait SplitIter: DoubleEndedIterator { /// Mark the underlying iterator as complete, extracting the remaining /// portion of the slice. - fn finish(&mut self) -> Option; + fn finish(&mut self) -> Option< ::Item>; } /// An iterator over subslices separated by elements that match a predicate @@ -892,7 +894,9 @@ impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool { } #[experimental = "needs review"] -impl<'a, T, P> Iterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool { + type Item = &'a [T]; + #[inline] fn next(&mut self) -> Option<&'a [T]> { if self.finished { return None; } @@ -918,7 +922,7 @@ impl<'a, T, P> Iterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool } #[experimental = "needs review"] -impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { if self.finished { return None; } @@ -934,7 +938,7 @@ impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Split<'a, T, P> where P: FnMut(& } } -impl<'a, T, P> SplitIter<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> SplitIter for Split<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn finish(&mut self) -> Option<&'a [T]> { if self.finished { None } else { self.finished = true; Some(self.v) } @@ -950,7 +954,7 @@ pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool { finished: bool } -impl<'a, T, P> SplitIter<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> SplitIter for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn finish(&mut self) -> Option<&'a mut [T]> { if self.finished { @@ -963,7 +967,9 @@ impl<'a, T, P> SplitIter<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) } #[experimental = "needs review"] -impl<'a, T, P> Iterator<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { +impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { + type Item = &'a mut [T]; + #[inline] fn next(&mut self) -> Option<&'a mut [T]> { if self.finished { return None; } @@ -996,7 +1002,7 @@ impl<'a, T, P> Iterator<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) - } #[experimental = "needs review"] -impl<'a, T, P> DoubleEndedIterator<&'a mut [T]> for SplitMut<'a, T, P> where +impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool, { #[inline] @@ -1029,9 +1035,11 @@ struct GenericSplitN { } #[experimental = "needs review"] -impl> Iterator for GenericSplitN { +impl> Iterator for GenericSplitN { + type Item = T; + #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.count == 0 { self.iter.finish() } else { @@ -1075,9 +1083,11 @@ pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { macro_rules! forward_iterator { ($name:ident: $elem:ident, $iter_of:ty) => { - impl<'a, $elem, P> Iterator<$iter_of> for $name<'a, $elem, P> where + impl<'a, $elem, P> Iterator for $name<'a, $elem, P> where P: FnMut(&T) -> bool { + type Item = $iter_of; + #[inline] fn next(&mut self) -> Option<$iter_of> { self.inner.next() @@ -1104,7 +1114,9 @@ pub struct Windows<'a, T:'a> { size: uint } -impl<'a, T> Iterator<&'a [T]> for Windows<'a, T> { +impl<'a, T> Iterator for Windows<'a, T> { + type Item = &'a [T]; + #[inline] fn next(&mut self) -> Option<&'a [T]> { if self.size > self.v.len() { @@ -1140,7 +1152,9 @@ pub struct Chunks<'a, T:'a> { } #[experimental = "needs review"] -impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> { +impl<'a, T> Iterator for Chunks<'a, T> { + type Item = &'a [T]; + #[inline] fn next(&mut self) -> Option<&'a [T]> { if self.v.len() == 0 { @@ -1167,7 +1181,7 @@ impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> { } #[experimental = "needs review"] -impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> { +impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { if self.v.len() == 0 { @@ -1183,7 +1197,7 @@ impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> { } #[experimental = "needs review"] -impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> { +impl<'a, T> RandomAccessIterator for Chunks<'a, T> { #[inline] fn indexable(&self) -> uint { self.v.len()/self.size + if self.v.len() % self.size != 0 { 1 } else { 0 } @@ -1213,7 +1227,9 @@ pub struct ChunksMut<'a, T:'a> { } #[experimental = "needs review"] -impl<'a, T> Iterator<&'a mut [T]> for ChunksMut<'a, T> { +impl<'a, T> Iterator for ChunksMut<'a, T> { + type Item = &'a mut [T]; + #[inline] fn next(&mut self) -> Option<&'a mut [T]> { if self.v.len() == 0 { @@ -1241,7 +1257,7 @@ impl<'a, T> Iterator<&'a mut [T]> for ChunksMut<'a, T> { } #[experimental = "needs review"] -impl<'a, T> DoubleEndedIterator<&'a mut [T]> for ChunksMut<'a, T> { +impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut [T]> { if self.v.len() == 0 { diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f4fe86a0d7e..8df072c9d46 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -37,7 +37,7 @@ use uint; macro_rules! delegate_iter { (exact $te:ty in $ti:ty) => { delegate_iter!{$te in $ti} - impl<'a> ExactSizeIterator<$te> for $ti { + impl<'a> ExactSizeIterator for $ti { #[inline] fn rposition

(&mut self, predicate: P) -> Option where P: FnMut($te) -> bool{ self.0.rposition(predicate) @@ -49,7 +49,9 @@ macro_rules! delegate_iter { } }; ($te:ty in $ti:ty) => { - impl<'a> Iterator<$te> for $ti { + impl<'a> Iterator for $ti { + type Item = $te; + #[inline] fn next(&mut self) -> Option<$te> { self.0.next() @@ -59,7 +61,7 @@ macro_rules! delegate_iter { self.0.size_hint() } } - impl<'a> DoubleEndedIterator<$te> for $ti { + impl<'a> DoubleEndedIterator for $ti { #[inline] fn next_back(&mut self) -> Option<$te> { self.0.next_back() @@ -67,7 +69,9 @@ macro_rules! delegate_iter { } }; (pattern $te:ty in $ti:ty) => { - impl<'a, P: CharEq> Iterator<$te> for $ti { + impl<'a, P: CharEq> Iterator for $ti { + type Item = $te; + #[inline] fn next(&mut self) -> Option<$te> { self.0.next() @@ -77,7 +81,7 @@ macro_rules! delegate_iter { self.0.size_hint() } } - impl<'a, P: CharEq> DoubleEndedIterator<$te> for $ti { + impl<'a, P: CharEq> DoubleEndedIterator for $ti { #[inline] fn next_back(&mut self) -> Option<$te> { self.0.next_back() @@ -85,7 +89,9 @@ macro_rules! delegate_iter { } }; (pattern forward $te:ty in $ti:ty) => { - impl<'a, P: CharEq> Iterator<$te> for $ti { + impl<'a, P: CharEq> Iterator for $ti { + type Item = $te; + #[inline] fn next(&mut self) -> Option<$te> { self.0.next() @@ -275,7 +281,9 @@ fn unwrap_or_0(opt: Option<&u8>) -> u8 { } } -impl<'a> Iterator for Chars<'a> { +impl<'a> Iterator for Chars<'a> { + type Item = char; + #[inline] fn next(&mut self) -> Option { // Decode UTF-8, using the valid UTF-8 invariant @@ -318,7 +326,7 @@ impl<'a> Iterator for Chars<'a> { } } -impl<'a> DoubleEndedIterator for Chars<'a> { +impl<'a> DoubleEndedIterator for Chars<'a> { #[inline] fn next_back(&mut self) -> Option { let w = match self.iter.next_back() { @@ -359,7 +367,9 @@ pub struct CharIndices<'a> { iter: Chars<'a>, } -impl<'a> Iterator<(uint, char)> for CharIndices<'a> { +impl<'a> Iterator for CharIndices<'a> { + type Item = (uint, char); + #[inline] fn next(&mut self) -> Option<(uint, char)> { let (pre_len, _) = self.iter.iter.size_hint(); @@ -380,7 +390,7 @@ impl<'a> Iterator<(uint, char)> for CharIndices<'a> { } } -impl<'a> DoubleEndedIterator<(uint, char)> for CharIndices<'a> { +impl<'a> DoubleEndedIterator for CharIndices<'a> { #[inline] fn next_back(&mut self) -> Option<(uint, char)> { match self.iter.next_back() { @@ -463,7 +473,9 @@ impl<'a, Sep> CharSplits<'a, Sep> { } } -impl<'a, Sep: CharEq> Iterator<&'a str> for CharSplits<'a, Sep> { +impl<'a, Sep: CharEq> Iterator for CharSplits<'a, Sep> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { if self.finished { return None } @@ -495,8 +507,7 @@ impl<'a, Sep: CharEq> Iterator<&'a str> for CharSplits<'a, Sep> { } } -impl<'a, Sep: CharEq> DoubleEndedIterator<&'a str> -for CharSplits<'a, Sep> { +impl<'a, Sep: CharEq> DoubleEndedIterator for CharSplits<'a, Sep> { #[inline] fn next_back(&mut self) -> Option<&'a str> { if self.finished { return None } @@ -537,7 +548,9 @@ for CharSplits<'a, Sep> { } } -impl<'a, Sep: CharEq> Iterator<&'a str> for CharSplitsN<'a, Sep> { +impl<'a, Sep: CharEq> Iterator for CharSplitsN<'a, Sep> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { if self.count != 0 { @@ -864,7 +877,9 @@ pub struct SplitStr<'a> { #[deprecated = "Type is now named `SplitStr`"] pub type StrSplits<'a> = SplitStr<'a>; -impl<'a> Iterator<(uint, uint)> for MatchIndices<'a> { +impl<'a> Iterator for MatchIndices<'a> { + type Item = (uint, uint); + #[inline] fn next(&mut self) -> Option<(uint, uint)> { match self.searcher { @@ -878,7 +893,9 @@ impl<'a> Iterator<(uint, uint)> for MatchIndices<'a> { } } -impl<'a> Iterator<&'a str> for SplitStr<'a> { +impl<'a> Iterator for SplitStr<'a> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { if self.finished { return None; } @@ -1672,23 +1689,27 @@ impl<'a> Default for &'a str { fn default() -> &'a str { "" } } -impl<'a> Iterator<&'a str> for Lines<'a> { +impl<'a> Iterator for Lines<'a> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a> DoubleEndedIterator<&'a str> for Lines<'a> { +impl<'a> DoubleEndedIterator for Lines<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } } -impl<'a> Iterator<&'a str> for LinesAny<'a> { +impl<'a> Iterator for LinesAny<'a> { + type Item = &'a str; + #[inline] fn next(&mut self) -> Option<&'a str> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a> DoubleEndedIterator<&'a str> for LinesAny<'a> { +impl<'a> DoubleEndedIterator for LinesAny<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } }