Skip to content

Commit

Permalink
std::vec: correct .sort()'s doc-string and add some
Browse files Browse the repository at this point in the history
examples/clarification to others.
  • Loading branch information
huonw committed Dec 24, 2013
1 parent 5772401 commit cc4e707
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2215,17 +2215,25 @@ pub trait MutableVector<'a, T> {
/// Unsafely sets the element in index to the value
unsafe fn unsafe_set(self, index: uint, val: T);

/**
* Unchecked vector index assignment. Does not drop the
* old value and hence is only suitable when the vector
* is newly allocated.
*/
/// Unchecked vector index assignment. Does not drop the
/// old value and hence is only suitable when the vector
/// is newly allocated.
///
/// # Example
///
/// ```rust
/// let mut v = [~"foo", ~"bar"];
///
/// // memory leak! `~"bar"` is not deallocated.
/// unsafe { v.init_elem(1, ~"baz"); }
/// ```
unsafe fn init_elem(self, i: uint, val: T);

/// Copies data from `src` to `self`.
/// Copies raw bytes from `src` to `self`.
///
/// `self` and `src` must not overlap. Fails if `self` is
/// shorter than `src`.
/// This does not run destructors on the overwritten elements, and
/// ignores move semantics. `self` and `src` must not
/// overlap. Fails if `self` is shorter than `src`.
unsafe fn copy_memory(self, src: &[T]);
}

Expand Down Expand Up @@ -2370,8 +2378,25 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {

/// Trait for &[T] where T is Cloneable
pub trait MutableCloneableVector<T> {
/// Copies as many elements from `src` as it can into `self`
/// (the shorter of self.len() and src.len()). Returns the number of elements copied.
/// Copies as many elements from `src` as it can into `self` (the
/// shorter of `self.len()` and `src.len()`). Returns the number
/// of elements copied.
///
/// # Example
///
/// ```rust
/// use std::vec::MutableCloneableVector;
///
/// let mut dst = [0, 0, 0];
/// let src = [1, 2];
///
/// assert_eq!(dst.copy_from(src), 2);
/// assert_eq!(dst, [1, 2, 0]);
///
/// let src2 = [3, 4, 5, 6];
/// assert_eq!(dst.copy_from(src2), 3);
/// assert_eq!(dst, [3, 4, 5]);
/// ```
fn copy_from(self, &[T]) -> uint;
}

Expand All @@ -2390,7 +2415,7 @@ impl<'a, T:Clone> MutableCloneableVector<T> for &'a mut [T] {
pub trait MutableTotalOrdVector<T> {
/// Sort the vector, in place.
///
/// This is equivalent to `self.sort_by(std::vec::SortForward)`.
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
///
/// # Example
///
Expand Down

0 comments on commit cc4e707

Please sign in to comment.