Skip to content

Commit

Permalink
A couple of fixes to vec_ng docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler authored and thestinger committed Mar 20, 2014
1 parent 14f656d commit cdab8a7
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/libstd/vec.rs
Expand Up @@ -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;
Expand All @@ -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> {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
/// ```
Expand Down Expand Up @@ -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();
Expand Down

5 comments on commit cdab8a7

@bors
Copy link
Contributor

@bors bors commented on cdab8a7 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on cdab8a7 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/vec_ng = cdab8a7 into auto

@bors
Copy link
Contributor

@bors bors commented on cdab8a7 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/vec_ng = cdab8a7 merged ok, testing candidate = 4224147

@bors
Copy link
Contributor

@bors bors commented on cdab8a7 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on cdab8a7 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4224147

Please sign in to comment.