@@ -2143,26 +2143,69 @@ pub trait MutableVector<'a, T> {
2143
2143
*/
2144
2144
fn mut_pop_ref ( & mut self ) -> & ' a mut T ;
2145
2145
2146
- /**
2147
- * Swaps two elements in a vector
2148
- *
2149
- * # Arguments
2150
- *
2151
- * * a - The index of the first element
2152
- * * b - The index of the second element
2153
- */
2146
+ /// Swaps two elements in a vector.
2147
+ ///
2148
+ /// Fails if `a` or `b` are out of bounds.
2149
+ ///
2150
+ /// # Arguments
2151
+ ///
2152
+ /// * a - The index of the first element
2153
+ /// * b - The index of the second element
2154
+ ///
2155
+ /// # Example
2156
+ ///
2157
+ /// ```rust
2158
+ /// let mut v = ["a", "b", "c", "d"];
2159
+ /// v.swap(1, 3);
2160
+ /// assert_eq!(v, ["a", "d", "c", "b"]);
2161
+ /// ```
2154
2162
fn swap ( self , a : uint , b : uint ) ;
2155
2163
2156
- /**
2157
- * Divides one `&mut` into two. The first will
2158
- * contain all indices from `0..mid` (excluding the index `mid`
2159
- * itself) and the second will contain all indices from
2160
- * `mid..len` (excluding the index `len` itself).
2161
- */
2164
+
2165
+ /// Divides one `&mut` into two at an index.
2166
+ ///
2167
+ /// The first will contain all indices from `[0, mid)` (excluding
2168
+ /// the index `mid` itself) and the second will contain all
2169
+ /// indices from `[mid, len)` (excluding the index `len` itself).
2170
+ ///
2171
+ /// Fails if `mid > len`.
2172
+ ///
2173
+ /// # Example
2174
+ ///
2175
+ /// ```rust
2176
+ /// let mut v = [1, 2, 3, 4, 5, 6];
2177
+ ///
2178
+ /// // scoped to restrict the lifetime of the borrows
2179
+ /// {
2180
+ /// let (left, right) = v.mut_split_at(0);
2181
+ /// assert_eq!(left, &mut []);
2182
+ /// assert_eq!(right, &mut [1, 2, 3, 4, 5, 6]);
2183
+ /// }
2184
+ ///
2185
+ /// {
2186
+ /// let (left, right) = v.mut_split_at(2);
2187
+ /// assert_eq!(left, &mut [1, 2]);
2188
+ /// assert_eq!(right, &mut [3, 4, 5, 6]);
2189
+ /// }
2190
+ ///
2191
+ /// {
2192
+ /// let (left, right) = v.mut_split_at(6);
2193
+ /// assert_eq!(left, &mut [1, 2, 3, 4, 5, 6]);
2194
+ /// assert_eq!(right, &mut []);
2195
+ /// }
2196
+ /// ```
2162
2197
fn mut_split_at ( self , mid : uint ) -> ( & ' a mut [ T ] ,
2163
2198
& ' a mut [ T ] ) ;
2164
2199
2165
- /// Reverse the order of elements in a vector, in place
2200
+ /// Reverse the order of elements in a vector, in place.
2201
+ ///
2202
+ /// # Example
2203
+ ///
2204
+ /// ```rust
2205
+ /// let mut v = [1, 2, 3];
2206
+ /// v.reverse();
2207
+ /// assert_eq!(v, [3, 2, 1]);
2208
+ /// ```
2166
2209
fn reverse ( self ) ;
2167
2210
2168
2211
/// Sort the vector, in place, using `compare` to compare
@@ -2212,7 +2255,27 @@ pub trait MutableVector<'a, T> {
2212
2255
#[ inline]
2213
2256
fn as_mut_ptr ( self ) -> * mut T ;
2214
2257
2215
- /// Unsafely sets the element in index to the value
2258
+ /// Unsafely sets the element in index to the value.
2259
+ ///
2260
+ /// This performs no bounds checks, and it is undefined behaviour
2261
+ /// if `index` is larger than the length of `self`. However, it
2262
+ /// does run the destructor at `index`. It is equivalent to
2263
+ /// `self[index] = val`.
2264
+ ///
2265
+ /// # Example
2266
+ ///
2267
+ /// ```rust
2268
+ /// let mut v = ~[~"foo", ~"bar", ~"baz"];
2269
+ ///
2270
+ /// unsafe {
2271
+ /// // `~"baz"` is deallocated.
2272
+ /// v.unsafe_set(2, ~"qux");
2273
+ ///
2274
+ /// // Out of bounds: could cause a crash, or overwriting
2275
+ /// // other data, or something else.
2276
+ /// // v.unsafe_set(10, ~"oops");
2277
+ /// }
2278
+ /// ```
2216
2279
unsafe fn unsafe_set ( self , index : uint , val : T ) ;
2217
2280
2218
2281
/// Unchecked vector index assignment. Does not drop the
0 commit comments