0

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.

Herohtar
  • 5,347
  • 4
  • 31
  • 41
jkaczmarkiewicz
  • 1,500
  • 6
  • 17

1 Answers1

4

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

(y..x).rev()

this will produce desired range

jkaczmarkiewicz
  • 1,500
  • 6
  • 17