You're right, as defined, it cannot be negative. But it can be 0, and
if you subtract 1 from that then you get an overflow. Rust does not
protect you against that. You can't do:
let x: usize = -1;
But you can do:
let mut x: usize = 0;
x -= 1; // boom
I don't have a test case, but it happened to me this morning and crashed
my game. I think you generally avoid it by surrounding the map with
walls, but if you've got a map with open edges, it's definitely a thing
that can happen.
You're right, as defined, it cannot be negative. But it can be 0, and if you subtract 1 from that then you get an overflow. Rust does not protect you against that. You can't do:
But you can do:
I don't have a test case, but it happened to me this morning and crashed my game. I think you generally avoid it by surrounding the map with walls, but if you've got a map with open edges, it's definitely a thing that can happen.