Skip to content

Commit 53f6a4e

Browse files
committed
std: fix UnfoldrIterator cross-crate.
1 parent c989b79 commit 53f6a4e

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/libstd/iterator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ impl<'self, A, St> UnfoldrIterator<'self, A, St> {
788788
/// Creates a new iterator with the specified closure as the "iterator
789789
/// function" and an initial state to eventually pass to the iterator
790790
#[inline]
791-
pub fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
792-
-> UnfoldrIterator<'self, A, St> {
791+
pub fn new<'a>(f: &'a fn(&mut St) -> Option<A>, initial_state: St)
792+
-> UnfoldrIterator<'a, A, St> {
793793
UnfoldrIterator {
794794
f: f,
795795
state: initial_state
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::iterator::*;
12+
13+
// UnfoldrIterator had a bug with 'self that mean it didn't work
14+
// cross-crate
15+
16+
fn main() {
17+
fn count(st: &mut uint) -> Option<uint> {
18+
if *st < 10 {
19+
let ret = Some(*st);
20+
*st += 1;
21+
ret
22+
} else {
23+
None
24+
}
25+
}
26+
27+
let mut it = UnfoldrIterator::new(count, 0);
28+
let mut i = 0;
29+
for it.advance |counted| {
30+
assert_eq!(counted, i);
31+
i += 1;
32+
}
33+
assert_eq!(i, 10);
34+
}

0 commit comments

Comments
 (0)