Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Numerically decreasing iterator in Rust

I need an open-ended decreasing integer iterator in Rust. (..=n).rev() does not work. The closest I’ve found is std::iter::successors(Some(n), |n| Some(n - 1)), which seems needlessly convoluted.

Is there a clearer way to express this notion of a numerically decreasing iterator?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s not exactly open-ended, but you could use the minimum value for whatever integer type you’re targeting:

(i64::MIN..=n).rev()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading