Skip to content

Commit ba480cb

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

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/libcore/iter.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ pub trait IteratorExt<A>: Iterator<A> {
346346
/// ```
347347
#[inline]
348348
#[unstable = "waiting for unboxed closures"]
349-
fn scan<'r, St, B>(self, initial_state: St, f: |&mut St, A|: 'r -> Option<B>)
350-
-> Scan<'r, A, B, Self, St> {
349+
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<A, B, Self, St, F> where
350+
F: FnMut(&mut St, A) -> Option<B>,
351+
{
351352
Scan{iter: self, f: f, state: initial_state}
352353
}
353354

@@ -1833,16 +1834,19 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Take<T> {
18331834
/// An iterator to maintain state while iterating another iterator
18341835
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
18351836
#[unstable = "waiting for unboxed closures"]
1836-
pub struct Scan<'a, A, B, T, St> {
1837-
iter: T,
1838-
f: |&mut St, A|: 'a -> Option<B>,
1837+
pub struct Scan<A, B, I, St, F> where I: Iterator<A>, F: FnMut(&mut St, A) -> Option<B> {
1838+
iter: I,
1839+
f: F,
18391840

18401841
/// The current internal state to be passed to the closure next.
18411842
pub state: St,
18421843
}
18431844

18441845
#[unstable = "trait is unstable"]
1845-
impl<'a, A, B, T: Iterator<A>, St> Iterator<B> for Scan<'a, A, B, T, St> {
1846+
impl<A, B, I, St, F> Iterator<B> for Scan<A, B, I, St, F> where
1847+
I: Iterator<A>,
1848+
F: FnMut(&mut St, A) -> Option<B>,
1849+
{
18461850
#[inline]
18471851
fn next(&mut self) -> Option<B> {
18481852
self.iter.next().and_then(|a| (self.f)(&mut self.state, a))

0 commit comments

Comments
 (0)