about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2014-03-19 23:01:08 -0700
committerDaniel Micay <danielmicay@gmail.com>2014-03-20 05:44:25 -0400
commitcdab8a76f40969556ee1b86b8f107ec38cc137f9 (patch)
treef924d433fd2142fe0e927701697477d8e456e714 /src/libstd
parent14f656d1a79fb36ce5435976dd33f57dd09cb9ce (diff)
downloadrust-cdab8a76f40969556ee1b86b8f107ec38cc137f9.tar.gz
rust-cdab8a76f40969556ee1b86b8f107ec38cc137f9.zip
A couple of fixes to vec_ng docs
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/vec.rs38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 7a4a7da2a68..5f4f4960a93 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -7,7 +7,7 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
-//! A growable, owned vector
+//! An owned, growable vector.
 
 use cast::{forget, transmute};
 use clone::Clone;
@@ -30,18 +30,29 @@ use raw::Slice;
 use slice::{ImmutableEqVector, ImmutableVector, Items, MutItems, MutableVector};
 use slice::{MutableTotalOrdVector};
 
-/// An owned, growable vector
+/// An owned, growable vector.
 ///
-/// `Vec<T>` is the replacement for the deprecated `~[T]` type. The API is
-/// largely the same. The `vec!` macro is provided to make initialization
-/// easier.
+/// # Examples
 ///
-/// # Example
+/// ```rust
+/// # use std::vec::Vec;
+/// let mut vec = Vec::new();
+/// vec.push(1);
+/// vec.push(2);
+///
+/// assert_eq!(vec.len(), 2);
+/// assert_eq!(vec.get(0), &1);
+///
+/// assert_eq!(vec.pop(), Some(2));
+/// assert_eq!(vec.len(), 1);
+/// ```
+///
+/// The `vec!` macro is provided to make initialization more convenient:
 ///
 /// ```rust
 /// let mut vec = vec!(1, 2, 3);
 /// vec.push(4);
-/// println!("{}", vec); // prints [1, 2, 3, 4]
+/// assert_eq!(vec, vec!(1, 2, 3, 4));
 /// ```
 #[unsafe_no_drop_flag]
 pub struct Vec<T> {
@@ -87,7 +98,6 @@ impl<T> Vec<T> {
         }
     }
 
-
     /// Creates and initializes a `Vec`.
     ///
     /// Creates a `Vec` of size `length` and initializes the elements to the
@@ -767,13 +777,13 @@ impl<T> Vec<T> {
     ///
     /// # Example
     /// ```rust
-    /// let mut v = ~[~"foo", ~"bar", ~"baz", ~"qux"];
+    /// let mut v = vec!(~"foo", ~"bar", ~"baz", ~"qux");
     ///
     /// assert_eq!(v.swap_remove(1), Some(~"bar"));
-    /// assert_eq!(v, ~[~"foo", ~"qux", ~"baz"]);
+    /// assert_eq!(v, vec!(~"foo", ~"qux", ~"baz"));
     ///
     /// assert_eq!(v.swap_remove(0), Some(~"foo"));
-    /// assert_eq!(v, ~[~"baz", ~"qux"]);
+    /// assert_eq!(v, vec!(~"baz", ~"qux"));
     ///
     /// assert_eq!(v.swap_remove(2), None);
     /// ```
@@ -869,13 +879,13 @@ impl<T> Vec<T> {
     /// # Example
     ///
     /// ```rust
-    /// let mut v = ~[1, 2, 3];
+    /// let mut v = vec!(1, 2, 3);
     /// assert_eq!(v.remove(1), Some(2));
-    /// assert_eq!(v, ~[1, 3]);
+    /// assert_eq!(v, vec!(1, 3));
     ///
     /// assert_eq!(v.remove(4), None);
     /// // v is unchanged:
-    /// assert_eq!(v, ~[1, 3]);
+    /// assert_eq!(v, vec!(1, 3));
     /// ```
     pub fn remove(&mut self, index: uint) -> Option<T> {
         let len = self.len();