Skip to content

Commit 574138a

Browse files
committed
Move map to an inherent trait method (hits rust-lang/rust#53457)
1 parent 089fb6f commit 574138a

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/iter.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use {
44
};
55

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

89
pub trait PinIterator {
910
type Item;
@@ -26,6 +27,19 @@ pub trait PinIterator {
2627

2728
P(self)
2829
}
30+
31+
fn map<F, R>(self, mut f: F) -> PinIterator__Map<Self, F, R>
32+
where
33+
Self: Sized,
34+
F: FnMut(Self::Item) -> R,
35+
{
36+
#[ergo_pin]
37+
gen_iter! {
38+
for item in pin!(self).iter() {
39+
yield f(item);
40+
}
41+
}
42+
}
2943
}
3044

3145
pub trait FusedPinIterator: PinIterator {
@@ -38,18 +52,3 @@ impl<P: PinIterator + ?Sized> PinIterator for Pin<&mut P> {
3852
Pin::get_mut(self).as_mut().next()
3953
}
4054
}
41-
42-
// TODO: This should be a provided method on `PinIterator`, but existential
43-
// types + closures don't mix well currently.
44-
pub fn map<I, F, R>(iter: I, mut f: F) -> impl PinIterator<Item = R>
45-
where
46-
I: PinIterator,
47-
F: FnMut(I::Item) -> R,
48-
{
49-
#[ergo_pin]
50-
gen_iter! {
51-
for item in pin!(iter).iter() {
52-
yield f(item);
53-
}
54-
}
55-
}

0 commit comments

Comments
 (0)