Skip to content

Commit f0ca717

Browse files
committed
auto merge of #18475 : gamazeps/rust/toExtend, r=alexcrichton
Ensured that Extend & FromIterator are implemented for the libcollection. Removed the fact that FromIterator had to be implemented in order to implement Extend, as it did not make sense for LruCache (it needs to be given a size and there are no Default for LruCache). Changed the name from Extend to Extendable. Part of #18424
2 parents b80edf1 + a11f167 commit f0ca717

File tree

26 files changed

+57
-31
lines changed

26 files changed

+57
-31
lines changed

src/etc/vim/syntax/rust.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ syn keyword rustEnum Ordering
9393
syn keyword rustEnumVariant Less Equal Greater
9494
syn keyword rustTrait Collection Mutable Map MutableMap MutableSeq
9595
syn keyword rustTrait Set MutableSet
96-
syn keyword rustTrait FromIterator Extendable ExactSize
96+
syn keyword rustTrait FromIterator IntoIterator Extend ExactSize
9797
syn keyword rustTrait Iterator DoubleEndedIterator
9898
syn keyword rustTrait RandomAccessIterator CloneableIterator
9999
syn keyword rustTrait OrdIterator MutableDoubleEndedIterator

src/libcollections/binary_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
555555
}
556556
}
557557

558-
impl<T: Ord> Extendable<T> for BinaryHeap<T> {
558+
impl<T: Ord> Extend<T> for BinaryHeap<T> {
559559
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
560560
let (lower, _) = iter.size_hint();
561561

src/libcollections/bit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ impl FromIterator<bool> for Bitv {
835835
}
836836
}
837837

838-
impl Extendable<bool> for Bitv {
838+
impl Extend<bool> for Bitv {
839839
#[inline]
840840
fn extend<I: Iterator<bool>>(&mut self, mut iterator: I) {
841841
let (min, _) = iterator.size_hint();
@@ -1014,7 +1014,7 @@ impl FromIterator<bool> for BitvSet {
10141014
}
10151015
}
10161016

1017-
impl Extendable<bool> for BitvSet {
1017+
impl Extend<bool> for BitvSet {
10181018
#[inline]
10191019
fn extend<I: Iterator<bool>>(&mut self, iterator: I) {
10201020
let &BitvSet(ref mut self_bitv) = self;

src/libcollections/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
727727
}
728728
}
729729

730-
impl<K: Ord, V> Extendable<(K, V)> for BTreeMap<K, V> {
730+
impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
731731
#[inline]
732732
fn extend<T: Iterator<(K, V)>>(&mut self, mut iter: T) {
733733
for (k, v) in iter {

src/libcollections/btree/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<T: Ord> FromIterator<T> for BTreeSet<T> {
316316
}
317317
}
318318

319-
impl<T: Ord> Extendable<T> for BTreeSet<T> {
319+
impl<T: Ord> Extend<T> for BTreeSet<T> {
320320
#[inline]
321321
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
322322
for elem in iter {

src/libcollections/dlist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl<A> FromIterator<A> for DList<A> {
720720
}
721721
}
722722

723-
impl<A> Extendable<A> for DList<A> {
723+
impl<A> Extend<A> for DList<A> {
724724
fn extend<T: Iterator<A>>(&mut self, mut iterator: T) {
725725
for elt in iterator { self.push_back(elt); }
726726
}

src/libcollections/enum_set.rs

+16
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ impl<E:CLike> Iterator<E> for Items<E> {
235235
}
236236
}
237237

238+
impl<E:CLike> FromIterator<E> for EnumSet<E> {
239+
fn from_iter<I:Iterator<E>>(iterator: I) -> EnumSet<E> {
240+
let mut ret = EnumSet::new();
241+
ret.extend(iterator);
242+
ret
243+
}
244+
}
245+
246+
impl<E:CLike> Extend<E> for EnumSet<E> {
247+
fn extend<I: Iterator<E>>(&mut self, mut iterator: I) {
248+
for element in iterator {
249+
self.insert(element);
250+
}
251+
}
252+
}
253+
238254
#[cfg(test)]
239255
mod test {
240256
use std::prelude::*;

src/libcollections/ring_buf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl<A> FromIterator<A> for RingBuf<A> {
735735
}
736736
}
737737

738-
impl<A> Extendable<A> for RingBuf<A> {
738+
impl<A> Extend<A> for RingBuf<A> {
739739
fn extend<T: Iterator<A>>(&mut self, mut iterator: T) {
740740
for elt in iterator {
741741
self.push_back(elt);

src/libcollections/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,8 @@ impl FromIterator<char> for String {
683683
}
684684
}
685685

686-
#[experimental = "waiting on Extendable stabilization"]
687-
impl Extendable<char> for String {
686+
#[experimental = "waiting on Extend stabilization"]
687+
impl Extend<char> for String {
688688
fn extend<I:Iterator<char>>(&mut self, mut iterator: I) {
689689
for ch in iterator {
690690
self.push(ch)

src/libcollections/tree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for TreeMap<K, V> {
12601260
}
12611261
}
12621262

1263-
impl<K: Ord, V> Extendable<(K, V)> for TreeMap<K, V> {
1263+
impl<K: Ord, V> Extend<(K, V)> for TreeMap<K, V> {
12641264
#[inline]
12651265
fn extend<T: Iterator<(K, V)>>(&mut self, mut iter: T) {
12661266
for (k, v) in iter {

src/libcollections/tree/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ impl<T: Ord> FromIterator<T> for TreeSet<T> {
659659
}
660660
}
661661

662-
impl<T: Ord> Extendable<T> for TreeSet<T> {
662+
impl<T: Ord> Extend<T> for TreeSet<T> {
663663
#[inline]
664664
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
665665
for elem in iter {

src/libcollections/trie/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl<T> FromIterator<(uint, T)> for TrieMap<T> {
628628
}
629629
}
630630

631-
impl<T> Extendable<(uint, T)> for TrieMap<T> {
631+
impl<T> Extend<(uint, T)> for TrieMap<T> {
632632
fn extend<Iter: Iterator<(uint, T)>>(&mut self, mut iter: Iter) {
633633
for (k, v) in iter {
634634
self.insert(k, v);

src/libcollections/trie/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl FromIterator<uint> for TrieSet {
355355
}
356356
}
357357

358-
impl Extendable<uint> for TrieSet {
358+
impl Extend<uint> for TrieSet {
359359
fn extend<Iter: Iterator<uint>>(&mut self, mut iter: Iter) {
360360
for elem in iter {
361361
self.insert(elem);

src/libcollections/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ impl<T> FromIterator<T> for Vec<T> {
484484
}
485485
}
486486

487-
#[experimental = "waiting on Extendable stability"]
488-
impl<T> Extendable<T> for Vec<T> {
487+
#[experimental = "waiting on Extend stability"]
488+
impl<T> Extend<T> for Vec<T> {
489489
#[inline]
490490
fn extend<I: Iterator<T>>(&mut self, mut iterator: I) {
491491
let (lower, _) = iterator.size_hint();

src/libcollections/vec_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<V> FromIterator<(uint, V)> for VecMap<V> {
499499
}
500500
}
501501

502-
impl<V> Extendable<(uint, V)> for VecMap<V> {
502+
impl<V> Extend<(uint, V)> for VecMap<V> {
503503
fn extend<Iter: Iterator<(uint, V)>>(&mut self, mut iter: Iter) {
504504
for (k, v) in iter {
505505
self.insert(k, v);

src/libcore/iter.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use num::{Zero, One, CheckedAdd, CheckedSub, Saturating, ToPrimitive, Int};
6666
use ops::{Add, Mul, Sub};
6767
use option::{Option, Some, None};
6868
use uint;
69+
#[deprecated = "renamed to Extend"] pub use self::Extend as Extendable;
6970

7071
/// Conversion from an `Iterator`
7172
pub trait FromIterator<A> {
@@ -74,8 +75,8 @@ pub trait FromIterator<A> {
7475
}
7576

7677
/// A type growable from an `Iterator` implementation
77-
pub trait Extendable<A>: FromIterator<A> {
78-
/// Extend a container with the elements yielded by an iterator
78+
pub trait Extend<A> {
79+
/// Extend a container with the elements yielded by an arbitrary iterator
7980
fn extend<T: Iterator<A>>(&mut self, iterator: T);
8081
}
8182

src/libcore/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub use char::Char;
4848
pub use clone::Clone;
4949
pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
5050
pub use cmp::{Ordering, Less, Equal, Greater, Equiv};
51-
pub use iter::{FromIterator, Extendable};
51+
pub use iter::{FromIterator, Extend};
5252
pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
5353
pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
5454
pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};

src/librustdoc/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use clean::*;
12-
use std::iter::Extendable;
12+
use std::iter::Extend;
1313
use std::mem::{replace, swap};
1414

1515
pub trait DocFolder {

src/libstd/collections/hash/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cmp::{max, Eq, Equiv, PartialEq};
1515
use default::Default;
1616
use fmt::{mod, Show};
1717
use hash::{Hash, Hasher, RandomSipHasher};
18-
use iter::{mod, Iterator, FromIterator, Extendable};
18+
use iter::{mod, Iterator, FromIterator, Extend};
1919
use kinds::Sized;
2020
use mem::{mod, replace};
2121
use num;
@@ -1449,7 +1449,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> FromIterator<(K, V)> for Has
14491449
}
14501450
}
14511451

1452-
impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Extendable<(K, V)> for HashMap<K, V, H> {
1452+
impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Extend<(K, V)> for HashMap<K, V, H> {
14531453
fn extend<T: Iterator<(K, V)>>(&mut self, mut iter: T) {
14541454
for (k, v) in iter {
14551455
self.insert(k, v);

src/libstd/collections/hash/set.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use default::Default;
1616
use fmt::Show;
1717
use fmt;
1818
use hash::{Hash, Hasher, RandomSipHasher};
19-
use iter::{Iterator, FromIterator, FilterMap, Chain, Repeat, Zip, Extendable};
19+
use iter::{Iterator, FromIterator, FilterMap, Chain, Repeat, Zip, Extend};
2020
use iter;
2121
use option::{Some, None};
2222
use result::{Ok, Err};
@@ -574,7 +574,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> FromIterator<T> for HashSet<T,
574574
}
575575
}
576576

577-
impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> Extendable<T> for HashSet<T, H> {
577+
impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> Extend<T> for HashSet<T, H> {
578578
fn extend<I: Iterator<T>>(&mut self, mut iter: I) {
579579
for k in iter {
580580
self.insert(k);

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> {

src/libstd/io/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use io::{IoResult, IoError, FileStat, SeekStyle, Seek, Writer, Reader};
6060
use io::{Read, Truncate, SeekCur, SeekSet, ReadWrite, SeekEnd, Append};
6161
use io::UpdateIoError;
6262
use io;
63-
use iter::{Iterator, Extendable};
63+
use iter::{Iterator, Extend};
6464
use kinds::Send;
6565
use libc;
6666
use option::{Some, None, Option};

src/libstd/path/posix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1616
use from_str::FromStr;
1717
use hash;
1818
use io::Writer;
19-
use iter::{DoubleEndedIterator, AdditiveIterator, Extendable, Iterator, Map};
19+
use iter::{DoubleEndedIterator, AdditiveIterator, Extend, Iterator, Map};
2020
use option::{Option, None, Some};
2121
use str::Str;
2222
use str;

src/libstd/path/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1919
use from_str::FromStr;
2020
use hash;
2121
use io::Writer;
22-
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map};
22+
use iter::{AdditiveIterator, DoubleEndedIterator, Extend, Iterator, Map};
2323
use mem;
2424
use option::{Option, Some, None};
2525
use slice::{AsSlice, SlicePrelude};

src/libstd/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#[doc(no_inline)] pub use clone::Clone;
6464
#[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
6565
#[doc(no_inline)] pub use cmp::{Ordering, Less, Equal, Greater, Equiv};
66-
#[doc(no_inline)] pub use iter::{FromIterator, Extendable, ExactSize};
66+
#[doc(no_inline)] pub use iter::{FromIterator, Extend, ExactSize};
6767
#[doc(no_inline)] pub use iter::{Iterator, DoubleEndedIterator};
6868
#[doc(no_inline)] pub use iter::{RandomAccessIterator, CloneableIterator};
6969
#[doc(no_inline)] pub use iter::{OrdIterator, MutableDoubleEndedIterator};

src/libsyntax/util/small_vector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<T> FromIterator<T> for SmallVector<T> {
3333
}
3434
}
3535

36-
impl<T> Extendable<T> for SmallVector<T> {
36+
impl<T> Extend<T> for SmallVector<T> {
3737
fn extend<I: Iterator<T>>(&mut self, mut iter: I) {
3838
for val in iter {
3939
self.push(val);

0 commit comments

Comments
 (0)