Open iosmanthus opened 6 years ago
std::iter::Step
is still unstable, tracked in https://github.com/rust-lang/rust/issues/42168.
That's a big reason why the num-iter
crate exists, like its range
function. But if your endpoints are small enough to fit in primitive types, like your example, it might actually be faster to just iterate that way and then convert: (1..1000).map(BigInt::from)
If anyone reading this needs something like 0..
(RangeFrom
trait), here you go:
std::iter::successors(Some(BigUint::zero()), |n| Some(n + 1u8))
I love successors
because it's quite simple and flexible. It helped me refactor many loops into functional-style chains of data
Maybe it will be more convenient to write the following code after adding trait
Step
forBigInt
: