2
2
3
3
Vectors are re-sizable arrays. Like slices, their size is not known at compile
4
4
time, but they can grow or shrink at any time. A vector is represented using
5
- 3 words: a pointer to the data, its length, and its capacity. The capacity
6
- indicates how much memory is reserved for the vector. The vector can grow as
7
- long as the length is smaller than the capacity. When this threshold needs to
8
- be surpassed, the vector is reallocated with a larger capacity.
5
+ 3 parameters:
6
+ - pointer to the data
7
+ - length
8
+ - capacity
9
+
10
+ The capacity indicates how much memory is reserved for the vector. The vector
11
+ can grow as long as the length is smaller than the capacity. When this threshold
12
+ needs to be surpassed, the vector is reallocated with a larger capacity.
9
13
10
14
``` rust,editable,ignore,mdbook-runnable
11
15
fn main() {
@@ -26,8 +30,8 @@ fn main() {
26
30
collected_iterator.push(0);
27
31
// FIXME ^ Comment out this line
28
32
29
- // The `len` method yields the current size of the vector
30
- println!("Vector size : {}", xs.len());
33
+ // The `len` method yields the number of elements currently stored in a vector
34
+ println!("Vector length : {}", xs.len());
31
35
32
36
// Indexing is done using the square brackets (indexing starts at 0)
33
37
println!("Second element: {}", xs[1]);
0 commit comments