From a11f16739f08ec480263ba549d510fffc8ce557e Mon Sep 17 00:00:00 2001 From: gamazeps Date: Sat, 8 Nov 2014 01:40:20 +0100 Subject: [PATCH] Implements Extend for EnumSet and LruCache Part of #18424 --- src/libcollections/enum_set.rs | 16 ++++++++++++++++ src/libstd/collections/lru_cache.rs | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 1acdaef9c91..7d2d298ee87 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -230,6 +230,22 @@ impl Iterator for Items { } } +impl FromIterator for EnumSet { + fn from_iter>(iterator: I) -> EnumSet { + let mut ret = EnumSet::new(); + ret.extend(iterator); + ret + } +} + +impl Extend for EnumSet { + fn extend>(&mut self, mut iterator: I) { + for element in iterator { + self.insert(element); + } + } +} + #[cfg(test)] mod test { use std::prelude::*; diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index aab0924e7e4..94bea37d187 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -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 LruCache { /// 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 Extend<(K, V)> for LruCache { + fn extend>(&mut self, mut iter: T) { + for (k, v) in iter{ + self.insert(k, v); + } + } } impl fmt::Show for LruCache {