@@ -2215,17 +2215,25 @@ pub trait MutableVector<'a, T> {
22152215 /// Unsafely sets the element in index to the value
22162216 unsafe fn unsafe_set ( self , index : uint , val : T ) ;
22172217
2218- /**
2219- * Unchecked vector index assignment. Does not drop the
2220- * old value and hence is only suitable when the vector
2221- * is newly allocated.
2222- */
2218+ /// Unchecked vector index assignment. Does not drop the
2219+ /// old value and hence is only suitable when the vector
2220+ /// is newly allocated.
2221+ ///
2222+ /// # Example
2223+ ///
2224+ /// ```rust
2225+ /// let mut v = [~"foo", ~"bar"];
2226+ ///
2227+ /// // memory leak! `~"bar"` is not deallocated.
2228+ /// unsafe { v.init_elem(1, ~"baz"); }
2229+ /// ```
22232230 unsafe fn init_elem ( self , i : uint , val : T ) ;
22242231
2225- /// Copies data from `src` to `self`.
2232+ /// Copies raw bytes from `src` to `self`.
22262233 ///
2227- /// `self` and `src` must not overlap. Fails if `self` is
2228- /// shorter than `src`.
2234+ /// This does not run destructors on the overwritten elements, and
2235+ /// ignores move semantics. `self` and `src` must not
2236+ /// overlap. Fails if `self` is shorter than `src`.
22292237 unsafe fn copy_memory ( self , src : & [ T ] ) ;
22302238}
22312239
@@ -2370,8 +2378,25 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
23702378
23712379/// Trait for &[T] where T is Cloneable
23722380pub trait MutableCloneableVector < T > {
2373- /// Copies as many elements from `src` as it can into `self`
2374- /// (the shorter of self.len() and src.len()). Returns the number of elements copied.
2381+ /// Copies as many elements from `src` as it can into `self` (the
2382+ /// shorter of `self.len()` and `src.len()`). Returns the number
2383+ /// of elements copied.
2384+ ///
2385+ /// # Example
2386+ ///
2387+ /// ```rust
2388+ /// use std::vec::MutableCloneableVector;
2389+ ///
2390+ /// let mut dst = [0, 0, 0];
2391+ /// let src = [1, 2];
2392+ ///
2393+ /// assert_eq!(dst.copy_from(src), 2);
2394+ /// assert_eq!(dst, [1, 2, 0]);
2395+ ///
2396+ /// let src2 = [3, 4, 5, 6];
2397+ /// assert_eq!(dst.copy_from(src2), 3);
2398+ /// assert_eq!(dst, [3, 4, 5]);
2399+ /// ```
23752400 fn copy_from ( self , & [ T ] ) -> uint ;
23762401}
23772402
@@ -2390,7 +2415,7 @@ impl<'a, T:Clone> MutableCloneableVector<T> for &'a mut [T] {
23902415pub trait MutableTotalOrdVector < T > {
23912416 /// Sort the vector, in place.
23922417 ///
2393- /// This is equivalent to `self.sort_by(std::vec::SortForward )`.
2418+ /// This is equivalent to `self.sort_by(|a, b| a.cmp(b) )`.
23942419 ///
23952420 /// # Example
23962421 ///
0 commit comments