@@ -2215,17 +2215,25 @@ pub trait MutableVector<'a, T> {
2215
2215
/// Unsafely sets the element in index to the value
2216
2216
unsafe fn unsafe_set ( self , index : uint , val : T ) ;
2217
2217
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
+ /// ```
2223
2230
unsafe fn init_elem ( self , i : uint , val : T ) ;
2224
2231
2225
- /// Copies data from `src` to `self`.
2232
+ /// Copies raw bytes from `src` to `self`.
2226
2233
///
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`.
2229
2237
unsafe fn copy_memory ( self , src : & [ T ] ) ;
2230
2238
}
2231
2239
@@ -2370,8 +2378,25 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
2370
2378
2371
2379
/// Trait for &[T] where T is Cloneable
2372
2380
pub 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
+ /// ```
2375
2400
fn copy_from ( self , & [ T ] ) -> uint ;
2376
2401
}
2377
2402
@@ -2390,7 +2415,7 @@ impl<'a, T:Clone> MutableCloneableVector<T> for &'a mut [T] {
2390
2415
pub trait MutableTotalOrdVector < T > {
2391
2416
/// Sort the vector, in place.
2392
2417
///
2393
- /// This is equivalent to `self.sort_by(std::vec::SortForward )`.
2418
+ /// This is equivalent to `self.sort_by(|a, b| a.cmp(b) )`.
2394
2419
///
2395
2420
/// # Example
2396
2421
///
0 commit comments