Skip to content

Commit 51463c3

Browse files
author
Nick Hamann
committed
Improve std::vec module documentation.
This changes the std::vec module docs to use full sentences. It also adds an example for indexing vectors.
1 parent 45b9a34 commit 51463c3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/libcollections/vec.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,43 @@
1515
//!
1616
//! # Examples
1717
//!
18-
//! Explicitly creating a `Vec<T>` with `new()`:
18+
//! You can explicitly create a `Vec<T>` with `new()`:
1919
//!
2020
//! ```
2121
//! let xs: Vec<i32> = Vec::new();
2222
//! ```
2323
//!
24-
//! Using the `vec!` macro:
24+
//! ...or by using the `vec!` macro:
2525
//!
2626
//! ```
2727
//! let ys: Vec<i32> = vec![];
2828
//!
2929
//! let zs = vec![1i32, 2, 3, 4, 5];
3030
//! ```
3131
//!
32-
//! Push:
32+
//! You can `push` values onto the end of a vector (which will grow the vector as needed):
3333
//!
3434
//! ```
3535
//! let mut xs = vec![1i32, 2];
3636
//!
3737
//! xs.push(3);
3838
//! ```
3939
//!
40-
//! And pop:
40+
//! Popping values works in much the same way:
4141
//!
4242
//! ```
4343
//! let mut xs = vec![1i32, 2];
4444
//!
4545
//! let two = xs.pop();
4646
//! ```
47+
//!
48+
//! Vectors also support indexing (through the `Index` and `IndexMut` traits):
49+
//!
50+
//! ```
51+
//! let mut xs = vec![1i32, 2, 3];
52+
//! let three = xs[2];
53+
//! xs[1] = xs[1] + 5;
54+
//! ```
4755
4856
#![stable(feature = "rust1", since = "1.0.0")]
4957

0 commit comments

Comments
 (0)