1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-23 09:16:44 +02:00

Minor fixes (#579)

* order the Cat and Dog correctly in the vec

* make example editable

* patterns: capture vs. constant

* clarify notes on indexing a string
This commit is contained in:
Dustin J. Mitchell
2023-04-24 14:46:38 -04:00
committed by GitHub
parent 4266078684
commit 6744822454
3 changed files with 10 additions and 4 deletions

View File

@ -35,6 +35,8 @@ fn main() {
* `String` implements `Deref<Target = str>` which transparently gives it access to `str`'s methods.
* Write and compare `let s3 = s1.deref();` and `let s3 = &*s1`;.
* `String` is implemented as a wrapper around a vector of bytes, many of the operations you see supported on vectors are also supported on `String`, but with some extra guarantees.
* Compare the different ways to index a `String` by using `s3[i]` and `s3.chars().nth(i).unwrap()` where `i` is in-bound, out-of-bounds, and "on" the flag Unicode character.
* Compare the different ways to index a `String`:
* To a character by using `s3.chars().nth(i).unwrap()` where `i` is in-bound, out-of-bounds.
* To a substring by using `s3[0..4]`, where that slice is on character boundaries or not.
</details>