Skip to content

Commit 96a3443

Browse files
committed
Small cleanup to vec docs
Add the repeating form of the vec macro Remove unneeded literal annotations. Use more conventional variable names.
1 parent eb4cb6d commit 96a3443

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/libcollections/vec.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,41 @@
1818
//! You can explicitly create a `Vec<T>` with `new()`:
1919
//!
2020
//! ```
21-
//! let xs: Vec<i32> = Vec::new();
21+
//! let v: Vec<i32> = Vec::new();
2222
//! ```
2323
//!
2424
//! ...or by using the `vec!` macro:
2525
//!
2626
//! ```
27-
//! let ys: Vec<i32> = vec![];
27+
//! let v: Vec<i32> = vec![];
2828
//!
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
3032
//! ```
3133
//!
3234
//! You can `push` values onto the end of a vector (which will grow the vector as needed):
3335
//!
3436
//! ```
35-
//! let mut xs = vec![1i32, 2];
37+
//! let mut v = vec![1, 2];
3638
//!
37-
//! xs.push(3);
39+
//! v.push(3);
3840
//! ```
3941
//!
4042
//! Popping values works in much the same way:
4143
//!
4244
//! ```
43-
//! let mut xs = vec![1i32, 2];
45+
//! let mut v = vec![1, 2];
4446
//!
45-
//! let two = xs.pop();
47+
//! let two = v.pop();
4648
//! ```
4749
//!
4850
//! Vectors also support indexing (through the `Index` and `IndexMut` traits):
4951
//!
5052
//! ```
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;
5456
//! ```
5557
5658
#![stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)