1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-27 19:18:59 +02:00

Speaker notes for vec.md (#296)

* Speaker notes for vec.md

* Fix grammar and formatting

* Fix formatting and spelling.

---------

Co-authored-by: Andrew Walbran <qwandor@google.com>
This commit is contained in:
Charisee Chiw
2023-01-30 03:56:30 -08:00
committed by GitHub
parent 49d24f89cf
commit 601dc8258b

View File

@ -26,10 +26,16 @@ methods on a `Vec`.
<details> <details>
Notice how `Vec<T>` is a generic type too, but you don't have to specify `T` explicitly. * `Vec` is a type of collection, along with `String` and `HashMap`. The data it contains is stored
As always with Rust type inference, the `T` was established during the first `push` call. on the heap. This means the amount of data doesn't need to be known at compile time. It can grow
or shrink at runtime.
`vec![...]` is a canonical macro to use instead of `Vec::new()` and it supports * Notice how `Vec<T>` is a generic type too, but you don't have to specify `T` explicitly. As always
adding initial elements to the vector. with Rust type inference, the `T` was established during the first `push` call.
* `vec![...]` is a canonical macro to use instead of `Vec::new()` and it supports adding initial
elements to the vector.
* To index the vector you use `[` `]`, but they will panic if out of bounds. Alternatively, using
`get` will return an `Option`. The `pop` function will remove the last element.
* Show iterating over a vector and mutating the value:
`for e in &mut v { *e += 50; }`
</details> </details>