Skip to content

Commit a051ba1

Browse files
author
Jorge Aparicio
committed
libcore: use unboxed closures in the fields of FlatMap
1 parent ba480cb commit a051ba1

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/libcore/iter.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ pub trait IteratorExt<A>: Iterator<A> {
372372
/// ```
373373
#[inline]
374374
#[unstable = "waiting for unboxed closures"]
375-
fn flat_map<'r, B, U: Iterator<B>>(self, f: |A|: 'r -> U)
376-
-> FlatMap<'r, A, Self, U> {
375+
fn flat_map<B, U, F>(self, f: F) -> FlatMap<A, B, Self, U, F> where
376+
U: Iterator<B>,
377+
F: FnMut(A) -> U,
378+
{
377379
FlatMap{iter: self, f: f, frontiter: None, backiter: None }
378380
}
379381

@@ -1864,15 +1866,19 @@ impl<A, B, I, St, F> Iterator<B> for Scan<A, B, I, St, F> where
18641866
///
18651867
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
18661868
#[unstable = "waiting for unboxed closures"]
1867-
pub struct FlatMap<'a, A, T, U> {
1868-
iter: T,
1869-
f: |A|: 'a -> U,
1869+
pub struct FlatMap<A, B, I, U, F> where I: Iterator<A>, U: Iterator<B>, F: FnMut(A) -> U {
1870+
iter: I,
1871+
f: F,
18701872
frontiter: Option<U>,
18711873
backiter: Option<U>,
18721874
}
18731875

18741876
#[unstable = "trait is unstable"]
1875-
impl<'a, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for FlatMap<'a, A, T, U> {
1877+
impl<A, B, I, U, F> Iterator<B> for FlatMap<A, B, I, U, F> where
1878+
I: Iterator<A>,
1879+
U: Iterator<B>,
1880+
F: FnMut(A) -> U,
1881+
{
18761882
#[inline]
18771883
fn next(&mut self) -> Option<B> {
18781884
loop {
@@ -1901,10 +1907,11 @@ impl<'a, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for FlatMap<'a, A, T,
19011907
}
19021908

19031909
#[unstable = "trait is unstable"]
1904-
impl<'a,
1905-
A, T: DoubleEndedIterator<A>,
1906-
B, U: DoubleEndedIterator<B>> DoubleEndedIterator<B>
1907-
for FlatMap<'a, A, T, U> {
1910+
impl<A, B, I, U, F> DoubleEndedIterator<B> for FlatMap<A, B, I, U, F> where
1911+
I: DoubleEndedIterator<A>,
1912+
U: DoubleEndedIterator<B>,
1913+
F: FnMut(A) -> U,
1914+
{
19081915
#[inline]
19091916
fn next_back(&mut self) -> Option<B> {
19101917
loop {

0 commit comments

Comments
 (0)