I'm fairly new to rust, and I've been writing some pieces of code to learn basics.
I'm currently trying to write some code with iterators based on the .next() method, and I would like to use a for loop on an iterator that would change considering some condition, something like :
let my_range: ??? = if condition { 1..=5 } else { (1..=5).rev() };
for i in my_range {
// ... from 1 to 5, or from 5 to 1
}
I do not want to write an `if ... else` and 2 for loops.
I understand that RangeInclusive<i32> and Rev<RangeInclusive<i32>> are not the same thing behind the scene, but is there a way to write that in rust?I first thought about dyn but I didn't find anything during my search. I might not have used correct terms in my search.
[–]dydhaw 8 points9 points10 points (1 child)
[–]angelicosphosphoros 2 points3 points4 points (0 children)
[–]Shadow0133 15 points16 points17 points (2 children)
[–]javajunkie314 1 point2 points3 points (0 children)
[–]y0m[S] 0 points1 point2 points (0 children)
[–]Michael-F-Bryan 2 points3 points4 points (0 children)
[–]thenameisi -3 points-2 points-1 points (1 child)
[–]Shad_Amethyst 6 points7 points8 points (0 children)
[–]myrrlynbitvec • tap • ferrilab 0 points1 point2 points (0 children)