Skip to content

Commit

Permalink
Move map to an inherent trait method (hits rust-lang/rust#53457)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Feb 6, 2019
1 parent 089fb6f commit 574138a
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
};

existential type PinIterator__Iter<I: PinIterator>: Iterator<Item = I::Item>;
existential type PinIterator__Map<I: PinIterator, F: FnMut(I::Item) -> R, R>: PinIterator<Item = R>;

pub trait PinIterator {
type Item;
Expand All @@ -26,6 +27,19 @@ pub trait PinIterator {

P(self)
}

fn map<F, R>(self, mut f: F) -> PinIterator__Map<Self, F, R>
where
Self: Sized,
F: FnMut(Self::Item) -> R,
{
#[ergo_pin]
gen_iter! {
for item in pin!(self).iter() {
yield f(item);
}
}
}
}

pub trait FusedPinIterator: PinIterator {
Expand All @@ -38,18 +52,3 @@ impl<P: PinIterator + ?Sized> PinIterator for Pin<&mut P> {
Pin::get_mut(self).as_mut().next()
}
}

// TODO: This should be a provided method on `PinIterator`, but existential
// types + closures don't mix well currently.
pub fn map<I, F, R>(iter: I, mut f: F) -> impl PinIterator<Item = R>
where
I: PinIterator,
F: FnMut(I::Item) -> R,
{
#[ergo_pin]
gen_iter! {
for item in pin!(iter).iter() {
yield f(item);
}
}
}

0 comments on commit 574138a

Please sign in to comment.