1 // Copyright 2017 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.
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.
11 fn iterate<T, F>(initial: T, f: F) -> Iterate<T, F> {
18 pub struct Iterate<T, F> {
23 impl<T: Clone, F> Iterator for Iterate<T, F> where F: Fn(&T) -> T {
27 fn next(&mut self) -> Option<Self::Item> {
28 self.state = (self.f)(&self.state);
29 Some(self.state.clone())
32 fn size_hint(&self) -> (usize, Option<usize>) { (std::usize::MAX, None) }
36 let a = iterate(0, |x| x+1);
37 println!("{:?}", a.iter().take(10).collect::<Vec<usize>>());
38 //~^ ERROR no method named `iter` found for type `Iterate<{integer}