90a2e5e3fe
Part of #68490. Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros. For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed.
30 lines
646 B
Rust
30 lines
646 B
Rust
fn iterate<T, F>(initial: T, f: F) -> Iterate<T, F> {
|
|
Iterate {
|
|
state: initial,
|
|
f: f,
|
|
}
|
|
}
|
|
|
|
pub struct Iterate<T, F> {
|
|
state: T,
|
|
f: F
|
|
}
|
|
|
|
impl<T: Clone, F> Iterator for Iterate<T, F> where F: Fn(&T) -> T {
|
|
type Item = T;
|
|
|
|
#[inline]
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
self.state = (self.f)(&self.state);
|
|
Some(self.state.clone())
|
|
}
|
|
#[inline]
|
|
fn size_hint(&self) -> (usize, Option<usize>) { (usize::MAX, None) }
|
|
}
|
|
|
|
fn main() {
|
|
let a = iterate(0, |x| x+1);
|
|
println!("{:?}", a.iter().take(10).collect::<Vec<usize>>());
|
|
//~^ ERROR no method named `iter` found
|
|
}
|