|
18 | 18 | //! You can explicitly create a `Vec<T>` with `new()`:
|
19 | 19 | //!
|
20 | 20 | //! ```
|
21 |
| -//! let xs: Vec<i32> = Vec::new(); |
| 21 | +//! let v: Vec<i32> = Vec::new(); |
22 | 22 | //! ```
|
23 | 23 | //!
|
24 | 24 | //! ...or by using the `vec!` macro:
|
25 | 25 | //!
|
26 | 26 | //! ```
|
27 |
| -//! let ys: Vec<i32> = vec![]; |
| 27 | +//! let v: Vec<i32> = vec![]; |
28 | 28 | //!
|
29 |
| -//! let zs = vec![1i32, 2, 3, 4, 5]; |
| 29 | +//! let v = vec![1, 2, 3, 4, 5]; |
| 30 | +//! |
| 31 | +//! let v = vec![0; 10]; // ten zeroes |
30 | 32 | //! ```
|
31 | 33 | //!
|
32 | 34 | //! You can `push` values onto the end of a vector (which will grow the vector as needed):
|
33 | 35 | //!
|
34 | 36 | //! ```
|
35 |
| -//! let mut xs = vec![1i32, 2]; |
| 37 | +//! let mut v = vec![1, 2]; |
36 | 38 | //!
|
37 |
| -//! xs.push(3); |
| 39 | +//! v.push(3); |
38 | 40 | //! ```
|
39 | 41 | //!
|
40 | 42 | //! Popping values works in much the same way:
|
41 | 43 | //!
|
42 | 44 | //! ```
|
43 |
| -//! let mut xs = vec![1i32, 2]; |
| 45 | +//! let mut v = vec![1, 2]; |
44 | 46 | //!
|
45 |
| -//! let two = xs.pop(); |
| 47 | +//! let two = v.pop(); |
46 | 48 | //! ```
|
47 | 49 | //!
|
48 | 50 | //! Vectors also support indexing (through the `Index` and `IndexMut` traits):
|
49 | 51 | //!
|
50 | 52 | //! ```
|
51 |
| -//! let mut xs = vec![1i32, 2, 3]; |
52 |
| -//! let three = xs[2]; |
53 |
| -//! xs[1] = xs[1] + 5; |
| 53 | +//! let mut v = vec![1, 2, 3]; |
| 54 | +//! let three = v[2]; |
| 55 | +//! v[1] = v[1] + 5; |
54 | 56 | //! ```
|
55 | 57 |
|
56 | 58 | #![stable(feature = "rust1", since = "1.0.0")]
|
|
0 commit comments