rust-embedded / book

Documentation on how to use the Rust Programming Language to develop firmware for bare metal (microcontroller) devices
https://docs.rust-embedded.org/book/
Apache License 2.0
1.08k stars 173 forks source link

Bad example to show indices begin at 0 #363

Closed CAESIUS-TIM closed 9 months ago

CAESIUS-TIM commented 9 months ago

https://github.com/rust-embedded/book/blob/22bca3d0f6e9b9b556689b54ce96f25b46ecd1b3/src/start/panicking.md?plain=1#L90

The given example doesn't effectively show that in Rust, indices start from 0; it might even give the impression that indices begin at 1.

A common mistake is forgetting to subtract 1, as seen here: Right: let i = xs.len() - 1; Wrong: let i = xs.len();