Skip to content

Commit

Permalink
Make VecMap::into_iter consume the VecMap
Browse files Browse the repository at this point in the history
This is a breaking change. To fix it you should pass the VecMap by value
instead of by reference.

[breaking-change]
  • Loading branch information
aochagavia committed Jan 19, 2015
1 parent bd8a43c commit 2366dee
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/libcollections/vec_map.rs
Expand Up @@ -265,7 +265,7 @@ impl<V> VecMap<V> {
}

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

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

/// Return the number of elements in the map.
Expand Down

0 comments on commit 2366dee

Please sign in to comment.