Skip to content

Commit 2366dee

Browse files
committed
Make VecMap::into_iter consume the VecMap
This is a breaking change. To fix it you should pass the VecMap by value instead of by reference. [breaking-change]
1 parent bd8a43c commit 2366dee

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/libcollections/vec_map.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<V> VecMap<V> {
265265
}
266266

267267
/// Returns an iterator visiting all key-value pairs in ascending order by
268-
/// the keys, emptying (but not consuming) the original `VecMap`.
268+
/// the keys, consuming the original `VecMap`.
269269
/// The iterator's element type is `(uint, &'r V)`.
270270
///
271271
/// # Examples
@@ -284,14 +284,13 @@ impl<V> VecMap<V> {
284284
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
285285
/// ```
286286
#[stable]
287-
pub fn into_iter(&mut self) -> IntoIter<V> {
287+
pub fn into_iter(self) -> IntoIter<V> {
288288
fn filter<A>((i, v): (uint, Option<A>)) -> Option<(uint, A)> {
289289
v.map(|v| (i, v))
290290
}
291291
let filter: fn((uint, Option<V>)) -> Option<(uint, V)> = filter; // coerce to fn ptr
292292

293-
let values = replace(&mut self.v, vec!());
294-
IntoIter { iter: values.into_iter().enumerate().filter_map(filter) }
293+
IntoIter { iter: self.v.into_iter().enumerate().filter_map(filter) }
295294
}
296295

297296
/// Return the number of elements in the map.

0 commit comments

Comments
 (0)