Skip to content

Commit a11f167

Browse files
committed
Implements Extend for EnumSet and LruCache
Part of #18424
1 parent 16c8cd9 commit a11f167

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/libcollections/enum_set.rs

+16
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ impl<E:CLike> Iterator<E> for Items<E> {
230230
}
231231
}
232232

233+
impl<E:CLike> FromIterator<E> for EnumSet<E> {
234+
fn from_iter<I:Iterator<E>>(iterator: I) -> EnumSet<E> {
235+
let mut ret = EnumSet::new();
236+
ret.extend(iterator);
237+
ret
238+
}
239+
}
240+
241+
impl<E:CLike> Extend<E> for EnumSet<E> {
242+
fn extend<I: Iterator<E>>(&mut self, mut iterator: I) {
243+
for element in iterator {
244+
self.insert(element);
245+
}
246+
}
247+
}
248+
233249
#[cfg(test)]
234250
mod test {
235251
use std::prelude::*;

src/libstd/collections/lru_cache.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use cmp::{PartialEq, Eq};
4141
use collections::HashMap;
4242
use fmt;
4343
use hash::Hash;
44-
use iter::{range, Iterator};
44+
use iter::{range, Iterator, Extend};
4545
use mem;
4646
use ops::Drop;
4747
use option::{Some, None, Option};
@@ -329,6 +329,15 @@ impl<K: Hash + Eq, V> LruCache<K, V> {
329329
/// Clear the cache of all key-value pairs.
330330
#[unstable = "matches collection reform specification, waiting for dust to settle"]
331331
pub fn clear(&mut self) { self.map.clear(); }
332+
333+
}
334+
335+
impl<K: Hash + Eq, V> Extend<(K, V)> for LruCache<K, V> {
336+
fn extend<T: Iterator<(K, V)>>(&mut self, mut iter: T) {
337+
for (k, v) in iter{
338+
self.insert(k, v);
339+
}
340+
}
332341
}
333342

334343
impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for LruCache<A, B> {

0 commit comments

Comments
 (0)