1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-24 22:32:56 +02:00

Removes out of bounds checks for simplicity

Removes the out of bounds checks to keep the notes simple.
This commit is contained in:
Robin Stringer 2023-01-11 14:35:20 +00:00 committed by GitHub
parent 587645db6c
commit 41bb8acf3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,19 +35,7 @@ Arrays:
*We can use literals to assign values to arrays.
*Demonstrate out of bounds errors by setting n to different values
```
a[n+15] = 11 // index out of bounds error since len is 10
```
*Efficient way to check n is in bounds:
```
assert!(n+20 < a.len()); // panics
```
*In the main function, the print statement asks for the debug implementation with the `?` format parameter: `{a}` gives default output, `{a:?}` gives debug output.
*In the main function, the print statement asks for the debug implementation with the `?` format parameter: `{a}` gives the default output, `{a:?}` gives the debug output.
*Adding `#`, eg `{a:#?}`, invokes a "pretty printing" format, which can be easier to read.