From 51463c3b17749801e80513d297351ede0f683418 Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Sun, 3 May 2015 23:47:10 -0500 Subject: [PATCH] Improve std::vec module documentation. This changes the std::vec module docs to use full sentences. It also adds an example for indexing vectors. --- src/libcollections/vec.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 33de6b7973672..ecb07582932cd 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -15,13 +15,13 @@ //! //! # Examples //! -//! Explicitly creating a `Vec` with `new()`: +//! You can explicitly create a `Vec` with `new()`: //! //! ``` //! let xs: Vec = Vec::new(); //! ``` //! -//! Using the `vec!` macro: +//! ...or by using the `vec!` macro: //! //! ``` //! let ys: Vec = 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")]