I\'d like to write this:
fn fibs() -> std::iter::Iterator {
return std::iter::iterate((1i, 1i), |(a, b)| { (b, a + b) }).map(|(a, _)| a)
}
There is not at present any way to return an abstract type such as Iterator
, just as you can’t assign that as the type of a variable (let x: Iterator
won’t compile for the same reasons).
This has been discussed and is certainly desired; when it is done it will probably be in the form fn fibs() -> impl Iterator
, but you can’t do that yet.