Skip to content

Commit

Permalink
Implements Extend for EnumSet and LruCache
Browse files Browse the repository at this point in the history
Part of #18424
  • Loading branch information
gamazeps committed Nov 8, 2014
1 parent 16c8cd9 commit a11f167
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/libcollections/enum_set.rs
Expand Up @@ -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::*;
Expand Down
11 changes: 10 additions & 1 deletion src/libstd/collections/lru_cache.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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> {
Expand Down

9 comments on commit a11f167

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at gamazeps@a11f167

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging gamazeps/rust/toExtend = a11f167 into auto

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gamazeps/rust/toExtend = a11f167 merged ok, testing candidate = 2a544ccc

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at gamazeps@a11f167

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging gamazeps/rust/toExtend = a11f167 into auto

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gamazeps/rust/toExtend = a11f167 merged ok, testing candidate = f0ca717

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a11f167 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = f0ca717

Please sign in to comment.