Rust 1.0 does not have generator functions, so you'd have to do it manually with explicit iterators.
First, rewrite your Python example as a class with a next()
method, since that is closer to the model you're likely to get in Rust. Then you can rewrite it in Rust with a struct that implements the Iterator
trait.
You might also be able to use a function that returns a closure to achieve a similar result, but I don't think it would be possible to have that implement the Iterator
trait (since it would require being called to generate a new result).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…