-1

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
  • 4,958
  • 4
  • 31
  • 39
jkaczmarkiewicz
  • 1,310
  • 4
  • 15

1 Answers1

1

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

(y..x).rev()

this will produce desired range

jkaczmarkiewicz
  • 1,310
  • 4
  • 15