I want to create a range from 2 arbitrary numbers. I would like to do this:
(a..=b)
But, as a > b
is a possibility, it won't work.
I tried building a helper function, but it won't work because the .rev()
trait will return a Rev<RangeInclusive<_>>
not a RangeInclusive<_>
.
fn create_range(a: usize, b: usize) -> ops::RangeInclusive<usize> {
if a <= b {
(a..=b)
} else {
(b..=a).rev()
}
}
How to do this more cleanly?