From 32228f3d5781f93cc6f6419c1d6de33c5d1ba6c6 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 6 Jun 2013 16:39:25 +1000 Subject: [PATCH] std: work-around for take/skip type inference (#6967) --- src/libstd/iterator.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 7be9e8c354e9..780a5a827d10 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -186,7 +186,7 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &5); /// assert!(it.next().is_none()); /// ~~~ - fn skip(self, n: uint) -> SkipIterator; + fn skip(self, n: uint) -> SkipIterator; /// Creates an iterator which yields the first `n` elements of this /// iterator, and then it will always return None. @@ -203,7 +203,7 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &3); /// assert!(it.next().is_none()); /// ~~~ - fn take(self, n: uint) -> TakeIterator; + fn take(self, n: uint) -> TakeIterator; /// Creates a new iterator which behaves in a similar fashion to foldl. /// There is a state which is passed between each iteration and can be @@ -386,12 +386,12 @@ impl> IteratorUtil for T { } #[inline(always)] - fn skip(self, n: uint) -> SkipIterator { + fn skip(self, n: uint) -> SkipIterator { SkipIterator{iter: self, n: n} } #[inline(always)] - fn take(self, n: uint) -> TakeIterator { + fn take(self, n: uint) -> TakeIterator { TakeIterator{iter: self, n: n} } @@ -739,13 +739,14 @@ impl<'self, A, T: Iterator> Iterator for TakeWhileIterator<'self, A, T> { } } -/// An iterator which skips over `n` elements of `iter` -pub struct SkipIterator { +/// An iterator which skips over `n` elements of `iter`. +// FIXME #6967: Dummy A parameter to get around type inference bug +pub struct SkipIterator { priv iter: T, priv n: uint } -impl> Iterator for SkipIterator { +impl> Iterator for SkipIterator { #[inline] fn next(&mut self) -> Option { let mut next = self.iter.next(); @@ -772,12 +773,13 @@ impl> Iterator for SkipIterator { } /// An iterator which only iterates over the first `n` iterations of `iter`. -pub struct TakeIterator { +// FIXME #6967: Dummy A parameter to get around type inference bug +pub struct TakeIterator { priv iter: T, priv n: uint } -impl> Iterator for TakeIterator { +impl> Iterator for TakeIterator { #[inline] fn next(&mut self) -> Option { let next = self.iter.next(); @@ -945,7 +947,7 @@ mod tests { let ys = [13, 15, 16, 17, 19, 20, 30]; let mut it = xs.iter().skip(5); let mut i = 0; - for it.advance |&x: &uint| { + for it.advance |&x| { assert_eq!(x, ys[i]); i += 1; } @@ -958,7 +960,7 @@ mod tests { let ys = [0u, 1, 2, 3, 5]; let mut it = xs.iter().take(5); let mut i = 0; - for it.advance |&x: &uint| { + for it.advance |&x| { assert_eq!(x, ys[i]); i += 1; }