Added impl FromIterator for Map

master
Avril 4 years ago
parent eb6e713c1d
commit 359ded0f60
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -154,6 +154,20 @@ where K: Collapse
}
}
impl<K: Collapse, V> std::iter::FromIterator<(K, V)> for Map<K,V>
{
fn from_iter<I: IntoIterator<Item=(K, V)>>(iter: I) -> Self
{
//TODO: Optimise this
let mut this = Self::new();
for (key, value) in iter.into_iter()
{
this.insert(key, value);
}
this
}
}
impl<K,V> IntoIterator for Page<K,V>
where K: Collapse
{

@ -23,6 +23,14 @@ fn macros()
assert_eq!(map1,map2);
}
#[test]
fn from_iter()
{
let m: Map<usize, ()> = (0..100).zip(std::iter::repeat(())).collect();
assert_eq!(m.len(), 100);
assert_eq!((0..100).sum::<usize>(), m.into_iter().map(|x| x.0).sum::<usize>());
}
#[test]
fn is_empty()
{

Loading…
Cancel
Save