Skip to content

Commit

Permalink
Merge pull request rust-lang#34 from xfix/extend-copy
Browse files Browse the repository at this point in the history
Implement Extend<(&K, &V)> for Copy types
  • Loading branch information
bluss authored Sep 11, 2017
2 parents ea4e6e1 + 2db46a8 commit 97f22a3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,16 @@ impl<K, V, S> Extend<(K, V)> for OrderMap<K, V, S>
}
}

impl<'a, K, V, S> Extend<(&'a K, &'a V)> for OrderMap<K, V, S>
where K: Hash + Eq + Copy,
V: Copy,
S: BuildHasher,
{
fn extend<I: IntoIterator<Item=(&'a K, &'a V)>>(&mut self, iterable: I) {
self.extend(iterable.into_iter().map(|(&key, &value)| (key, value)));
}
}

impl<K, V, S> Default for OrderMap<K, V, S>
where S: BuildHasher + Default,
{
Expand Down Expand Up @@ -1769,4 +1779,12 @@ mod tests {
assert_ne!(map_a, map_c);
assert_ne!(map_c, map_a);
}

#[test]
fn extend() {
let mut map = OrderMap::new();
map.extend(vec![(&1, &2), (&3, &4)]);
map.extend(vec![(5, 6)]);
assert_eq!(map.into_iter().collect::<Vec<_>>(), vec![(1, 2), (3, 4), (5, 6)]);
}
}

0 comments on commit 97f22a3

Please sign in to comment.