Create range higher to lower

Issue

I want to create range x..y where x > y. For eg 5..-10.

5..-10 produces empty range https://doc.rust-lang.org/std/ops/struct.Range.html

I created this questions to share my solution and potentially someone will come with better idea.

Solution

We can create valid range y..x (since x > y) and then reverse it

(y..x).rev()

this will produce desired range

Answered By – jkaczmarkiewicz

Answer Checked By – Clifford M. (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.