Rust doesn't always perform a bounds check. I think iterating over an array doesn't result in bounds check for every item. And if you need to access individual items by index, there are unsafe functions for unchecked access.
This is due to the fact that C++ does not do bounds checking. Languages like Java and python have bounds checking so if you try to access an out of bounds element, they throw an error. C++ design principle was that it shouldn't be slower than the equivalent C code, and C doesn't do array bounds checking.
Reading the basic introduction:
If you try to use a subscript that is not in the array, you will get an error: array access is bounds-checked at run-time.
Why does Rust check array bounds at runtime, when it seems most other checks occur at compile time?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With