Skip to content

Commit 11de947

Browse files
committed
Implement RFC 839 for VecMap
1 parent 467713b commit 11de947

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/libcollections/vec_map.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,13 @@ impl<V> Extend<(usize, V)> for VecMap<V> {
828828
}
829829
}
830830

831+
#[unstable(feature = "extend_ref", reason = "recently added")]
832+
impl<'a, V: Copy> Extend<(usize, &'a V)> for VecMap<V> {
833+
fn extend<I: IntoIterator<Item=(usize, &'a V)>>(&mut self, iter: I) {
834+
self.extend(iter.into_iter().map(|(key, &value)| (key, value)));
835+
}
836+
}
837+
831838
impl<V> Index<usize> for VecMap<V> {
832839
type Output = V;
833840

src/libcollectionstest/vec_map.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,22 @@ fn test_entry(){
493493
assert_eq!(map.len(), 6);
494494
}
495495

496+
#[test]
497+
fn test_extend_ref() {
498+
let mut a = VecMap::new();
499+
a.insert(1, "one");
500+
let mut b = VecMap::new();
501+
b.insert(2, "two");
502+
b.insert(3, "three");
503+
504+
a.extend(&b);
505+
506+
assert_eq!(a.len(), 3);
507+
assert_eq!(a[&1], "one");
508+
assert_eq!(a[&2], "two");
509+
assert_eq!(a[&3], "three");
510+
}
511+
496512
mod bench {
497513
use std::collections::VecMap;
498514

0 commit comments

Comments
 (0)