From b8aac408f1a2c9add2317e92004d911742ded6af Mon Sep 17 00:00:00 2001 From: andrei-papou Date: Wed, 3 Apr 2019 13:49:25 +0300 Subject: [PATCH 1/2] Forwarded some methods to `inner` iterator: - nth - collect - any - all - find - find_map --- src/iterators/mod.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index b9aab1aa9..7d1767551 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -13,6 +13,7 @@ mod windows; mod lanes; pub mod iter; +use std::iter::FromIterator; use std::marker::PhantomData; use std::ptr; @@ -388,6 +389,38 @@ impl<'a, A, D: Dimension> Iterator for Iter<'a, A, D> { { either!(self.inner, iter => iter.fold(init, g)) } + + fn nth(&mut self, n: usize) -> Option { + either_mut!(self.inner, iter => iter.nth(n)) + } + + fn collect>(self) -> B where Self: Sized { + either!(self.inner, iter => iter.collect()) + } + + fn all(&mut self, f: F) -> bool + where Self: Sized, F: FnMut(Self::Item) -> bool + { + either_mut!(self.inner, iter => iter.all(f)) + } + + fn any(&mut self, f: F) -> bool + where Self: Sized, F: FnMut(Self::Item) -> bool + { + either_mut!(self.inner, iter => iter.any(f)) + } + + fn find

(&mut self, predicate: P) -> Option + where Self: Sized, P: FnMut(&Self::Item) -> bool + { + either_mut!(self.inner, iter => iter.find(predicate)) + } + + fn find_map(&mut self, f: F) -> Option + where Self: Sized, F: FnMut(Self::Item) -> Option + { + either_mut!(self.inner, iter => iter.find_map(f)) + } } impl<'a, A> DoubleEndedIterator for Iter<'a, A, Ix1> { @@ -455,6 +488,38 @@ impl<'a, A, D: Dimension> Iterator for IterMut<'a, A, D> { { either!(self.inner, iter => iter.fold(init, g)) } + + fn nth(&mut self, n: usize) -> Option { + either_mut!(self.inner, iter => iter.nth(n)) + } + + fn collect>(self) -> B where Self: Sized { + either!(self.inner, iter => iter.collect()) + } + + fn all(&mut self, f: F) -> bool + where Self: Sized, F: FnMut(Self::Item) -> bool + { + either_mut!(self.inner, iter => iter.all(f)) + } + + fn any(&mut self, f: F) -> bool + where Self: Sized, F: FnMut(Self::Item) -> bool + { + either_mut!(self.inner, iter => iter.any(f)) + } + + fn find

(&mut self, predicate: P) -> Option + where Self: Sized, P: FnMut(&Self::Item) -> bool + { + either_mut!(self.inner, iter => iter.find(predicate)) + } + + fn find_map(&mut self, f: F) -> Option + where Self: Sized, F: FnMut(Self::Item) -> Option + { + either_mut!(self.inner, iter => iter.find_map(f)) + } } impl<'a, A> DoubleEndedIterator for IterMut<'a, A, Ix1> { From 927307a1b6db0c87e8c610416fac1831969f48ea Mon Sep 17 00:00:00 2001 From: andrei-papou Date: Thu, 11 Apr 2019 11:49:59 +0300 Subject: [PATCH 2/2] Removed Self bounds + forwarded more methods --- src/iterators/mod.rs | 52 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 7d1767551..c7e153864 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -394,33 +394,49 @@ impl<'a, A, D: Dimension> Iterator for Iter<'a, A, D> { either_mut!(self.inner, iter => iter.nth(n)) } - fn collect>(self) -> B where Self: Sized { + fn collect(self) -> B + where B: FromIterator + { either!(self.inner, iter => iter.collect()) } fn all(&mut self, f: F) -> bool - where Self: Sized, F: FnMut(Self::Item) -> bool + where F: FnMut(Self::Item) -> bool { either_mut!(self.inner, iter => iter.all(f)) } fn any(&mut self, f: F) -> bool - where Self: Sized, F: FnMut(Self::Item) -> bool + where F: FnMut(Self::Item) -> bool { either_mut!(self.inner, iter => iter.any(f)) } fn find

(&mut self, predicate: P) -> Option - where Self: Sized, P: FnMut(&Self::Item) -> bool + where P: FnMut(&Self::Item) -> bool { either_mut!(self.inner, iter => iter.find(predicate)) } fn find_map(&mut self, f: F) -> Option - where Self: Sized, F: FnMut(Self::Item) -> Option + where F: FnMut(Self::Item) -> Option { either_mut!(self.inner, iter => iter.find_map(f)) } + + fn count(self) -> usize { + either!(self.inner, iter => iter.count()) + } + + fn last(self) -> Option { + either!(self.inner, iter => iter.last()) + } + + fn position

(&mut self, predicate: P) -> Option + where P: FnMut(Self::Item) -> bool, + { + either_mut!(self.inner, iter => iter.position(predicate)) + } } impl<'a, A> DoubleEndedIterator for Iter<'a, A, Ix1> { @@ -493,33 +509,49 @@ impl<'a, A, D: Dimension> Iterator for IterMut<'a, A, D> { either_mut!(self.inner, iter => iter.nth(n)) } - fn collect>(self) -> B where Self: Sized { + fn collect(self) -> B + where B: FromIterator + { either!(self.inner, iter => iter.collect()) } fn all(&mut self, f: F) -> bool - where Self: Sized, F: FnMut(Self::Item) -> bool + where F: FnMut(Self::Item) -> bool { either_mut!(self.inner, iter => iter.all(f)) } fn any(&mut self, f: F) -> bool - where Self: Sized, F: FnMut(Self::Item) -> bool + where F: FnMut(Self::Item) -> bool { either_mut!(self.inner, iter => iter.any(f)) } fn find

(&mut self, predicate: P) -> Option - where Self: Sized, P: FnMut(&Self::Item) -> bool + where P: FnMut(&Self::Item) -> bool { either_mut!(self.inner, iter => iter.find(predicate)) } fn find_map(&mut self, f: F) -> Option - where Self: Sized, F: FnMut(Self::Item) -> Option + where F: FnMut(Self::Item) -> Option { either_mut!(self.inner, iter => iter.find_map(f)) } + + fn count(self) -> usize { + either!(self.inner, iter => iter.count()) + } + + fn last(self) -> Option { + either!(self.inner, iter => iter.last()) + } + + fn position

(&mut self, predicate: P) -> Option + where P: FnMut(Self::Item) -> bool, + { + either_mut!(self.inner, iter => iter.position(predicate)) + } } impl<'a, A> DoubleEndedIterator for IterMut<'a, A, Ix1> {