about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-05-05 09:24:03 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-05-05 09:24:03 +0530
commit86a858add58168faf42838e9852a0b5b012cd6be (patch)
tree378a6ead43c2860b79aa9fa46ab6b6a341506b8f
parent74130520fbd41755c0220436dc79a7b59863bdd7 (diff)
parent51463c3b17749801e80513d297351ede0f683418 (diff)
Rollup merge of #25087 - nham:improve_vec_docs, r=Gankro
 This commit does two things: it adds an example for indexing vectors, and it changes the \"Examples\" section to use full sentences.

This change was spurred by someone in the #rust IRC channel asking if there was a `.set()` method for changing the `i`-th value of a vector (they had missed that `Vec` implements `IndexMut`, which is easy to do if you're not aware of that trait).
-rw-r--r--src/libcollections/vec.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index 935648099a7..a2be8b81219 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -15,13 +15,13 @@
 //!
 //! # Examples
 //!
-//! Explicitly creating a `Vec<T>` with `new()`:
+//! You can explicitly create a `Vec<T>` with `new()`:
 //!
 //! ```
 //! let xs: Vec<i32> = Vec::new();
 //! ```
 //!
-//! Using the `vec!` macro:
+//! ...or by using the `vec!` macro:
 //!
 //! ```
 //! let ys: Vec<i32> = vec![];
@@ -29,7 +29,7 @@
 //! let zs = vec![1i32, 2, 3, 4, 5];
 //! ```
 //!
-//! Push:
+//! You can `push` values onto the end of a vector (which will grow the vector as needed):
 //!
 //! ```
 //! let mut xs = vec![1i32, 2];
@@ -37,13 +37,21 @@
 //! xs.push(3);
 //! ```
 //!
-//! And pop:
+//! Popping values works in much the same way:
 //!
 //! ```
 //! let mut xs = vec![1i32, 2];
 //!
 //! let two = xs.pop();
 //! ```
+//!
+//! Vectors also support indexing (through the `Index` and `IndexMut` traits):
+//!
+//! ```
+//! let mut xs = vec![1i32, 2, 3];
+//! let three = xs[2];
+//! xs[1] = xs[1] + 5;
+//! ```
 
 #![stable(feature = "rust1", since = "1.0.0")]