提交 801ae133 编写于 作者: J Jorge Aparicio

libcore: use unboxed closures in the fields of `Filter`

上级 44b419b8
......@@ -183,7 +183,7 @@ fn map<B, F: FnMut(A) -> B>(self, f: F) -> Map<A, B, Self, F> {
/// ```
#[inline]
#[unstable = "waiting for unboxed closures"]
fn filter<'r>(self, predicate: |&A|: 'r -> bool) -> Filter<'r, A, Self> {
fn filter<P>(self, predicate: P) -> Filter<A, Self, P> where P: FnMut(&A) -> bool {
Filter{iter: self, predicate: predicate}
}
......@@ -1438,13 +1438,13 @@ fn idx(&mut self, index: uint) -> Option<B> {
/// An iterator which filters the elements of `iter` with `predicate`
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[stable]
pub struct Filter<'a, A, T> {
iter: T,
predicate: |&A|: 'a -> bool
pub struct Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
iter: I,
predicate: P,
}
#[unstable = "trait is unstable"]
impl<'a, A, T: Iterator<A>> Iterator<A> for Filter<'a, A, T> {
impl<A, I, P> Iterator<A> for Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
#[inline]
fn next(&mut self) -> Option<A> {
for x in self.iter {
......@@ -1465,7 +1465,10 @@ fn size_hint(&self) -> (uint, Option<uint>) {
}
#[unstable = "trait is unstable"]
impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Filter<'a, A, T> {
impl<A, I, P> DoubleEndedIterator<A> for Filter<A, I, P> where
I: DoubleEndedIterator<A>,
P: FnMut(&A) -> bool,
{
#[inline]
fn next_back(&mut self) -> Option<A> {
for x in self.iter.by_ref().rev() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册