Skip to content

Commit

Permalink
Implement RFC 839 for VecMap
Browse files Browse the repository at this point in the history
  • Loading branch information
jooert committed Jun 3, 2015
1 parent 467713b commit 11de947
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,13 @@ impl<V> Extend<(usize, V)> for VecMap<V> {
}
}

#[unstable(feature = "extend_ref", reason = "recently added")]
impl<'a, V: Copy> Extend<(usize, &'a V)> for VecMap<V> {
fn extend<I: IntoIterator<Item=(usize, &'a V)>>(&mut self, iter: I) {
self.extend(iter.into_iter().map(|(key, &value)| (key, value)));
}
}

impl<V> Index<usize> for VecMap<V> {
type Output = V;

Expand Down
16 changes: 16 additions & 0 deletions src/libcollectionstest/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,22 @@ fn test_entry(){
assert_eq!(map.len(), 6);
}

#[test]
fn test_extend_ref() {
let mut a = VecMap::new();
a.insert(1, "one");
let mut b = VecMap::new();
b.insert(2, "two");
b.insert(3, "three");

a.extend(&b);

assert_eq!(a.len(), 3);
assert_eq!(a[&1], "one");
assert_eq!(a[&2], "two");
assert_eq!(a[&3], "three");
}

mod bench {
use std::collections::VecMap;

Expand Down

0 comments on commit 11de947

Please sign in to comment.