Panicked at ‘attempt to subtract with overflow’ when cycling backwards though a list
As DK. points out, you don’t want wrapping semantics at the integer level: fn main() { let idx: usize = 0; let len = 10; let next_idx = idx.wrapping_sub(1) % len; println!(“{}”, next_idx) // Prints 5!!! } Instead, you want to use modulo logic to wrap around: let next_idx = (idx + len – 1) … Read more