Skip to content

Commit 801ae13

Browse files
author
Jorge Aparicio
committed
libcore: use unboxed closures in the fields of Filter
1 parent 44b419b commit 801ae13

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/libcore/iter.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub trait IteratorExt<A>: Iterator<A> {
183183
/// ```
184184
#[inline]
185185
#[unstable = "waiting for unboxed closures"]
186-
fn filter<'r>(self, predicate: |&A|: 'r -> bool) -> Filter<'r, A, Self> {
186+
fn filter<P>(self, predicate: P) -> Filter<A, Self, P> where P: FnMut(&A) -> bool {
187187
Filter{iter: self, predicate: predicate}
188188
}
189189

@@ -1438,13 +1438,13 @@ impl<A, B, I, F> RandomAccessIterator<B> for Map<A, B, I, F> where
14381438
/// An iterator which filters the elements of `iter` with `predicate`
14391439
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
14401440
#[stable]
1441-
pub struct Filter<'a, A, T> {
1442-
iter: T,
1443-
predicate: |&A|: 'a -> bool
1441+
pub struct Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
1442+
iter: I,
1443+
predicate: P,
14441444
}
14451445

14461446
#[unstable = "trait is unstable"]
1447-
impl<'a, A, T: Iterator<A>> Iterator<A> for Filter<'a, A, T> {
1447+
impl<A, I, P> Iterator<A> for Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
14481448
#[inline]
14491449
fn next(&mut self) -> Option<A> {
14501450
for x in self.iter {
@@ -1465,7 +1465,10 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for Filter<'a, A, T> {
14651465
}
14661466

14671467
#[unstable = "trait is unstable"]
1468-
impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Filter<'a, A, T> {
1468+
impl<A, I, P> DoubleEndedIterator<A> for Filter<A, I, P> where
1469+
I: DoubleEndedIterator<A>,
1470+
P: FnMut(&A) -> bool,
1471+
{
14691472
#[inline]
14701473
fn next_back(&mut self) -> Option<A> {
14711474
for x in self.iter.by_ref().rev() {

0 commit comments

Comments
 (0)