Rust by Example: Collections - Vectors
The type |
|
Initialize a new vector with the |
|
We can explicitly declare the type of the vector |
|
And also implicitly declare the type of the vector |
|
When you know the number beforehand you can create a vector by
calling |
|
Another possibility is to build a vector from the values produced by an
iterator by using the |
|
To access elements of a vector we can use the |
|
Or we can use the |
|
We can iterate over the elements of a vector using a |
|
To store different types in a vector we can use an enum |
|
|
|
|
|
Slicing a vector |
|
Insert an element at a specific index, shifting all elements after it to the right |
|
Remove an element at a specific index |
|
Popping the last element of a vector |
|
Clear a vector |
|
|