Implements Extend for EnumSet and LruCache

Part of #18424
This commit is contained in:
gamazeps 2014-11-08 01:40:20 +01:00
parent 16c8cd931c
commit a11f16739f
2 changed files with 26 additions and 1 deletions

View File

@ -230,6 +230,22 @@ impl<E:CLike> Iterator<E> for Items<E> {
}
}
impl<E:CLike> FromIterator<E> for EnumSet<E> {
fn from_iter<I:Iterator<E>>(iterator: I) -> EnumSet<E> {
let mut ret = EnumSet::new();
ret.extend(iterator);
ret
}
}
impl<E:CLike> Extend<E> for EnumSet<E> {
fn extend<I: Iterator<E>>(&mut self, mut iterator: I) {
for element in iterator {
self.insert(element);
}
}
}
#[cfg(test)]
mod test {
use std::prelude::*;

View File

@ -41,7 +41,7 @@ use cmp::{PartialEq, Eq};
use collections::HashMap;
use fmt;
use hash::Hash;
use iter::{range, Iterator};
use iter::{range, Iterator, Extend};
use mem;
use ops::Drop;
use option::{Some, None, Option};
@ -329,6 +329,15 @@ impl<K: Hash + Eq, V> LruCache<K, V> {
/// Clear the cache of all key-value pairs.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
pub fn clear(&mut self) { self.map.clear(); }
}
impl<K: Hash + Eq, V> Extend<(K, V)> for LruCache<K, V> {
fn extend<T: Iterator<(K, V)>>(&mut self, mut iter: T) {
for (k, v) in iter{
self.insert(k, v);
}
}
}
impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for LruCache<A, B> {