Skip to content

Commit 53487a0

Browse files
committed
std: Move the iterator param on FromIterator and Extendable to the method.
If they are on the trait then it is extremely annoying to use them as generic parameters to a function, e.g. with the iterator param on the trait itself, if one was to pass an Extendable<int> to a function that filled it either from a Range or a Map<VecIterator>, one needs to write something like: fn foo<E: Extendable<int, Range<int>> + Extendable<int, Map<&'self int, int, VecIterator<int>>> (e: &mut E, ...) { ... } since using a generic, i.e. `foo<E: Extendable<int, I>, I: Iterator<int>>` means that `foo` takes 2 type parameters, and the caller has to specify them (which doesn't work anyway, as they'll mismatch with the iterators used in `foo` itself). This patch changes it to: fn foo<E: Extendable<int>>(e: &mut E, ...) { ... }
1 parent 58021be commit 53487a0

11 files changed

+53
-54
lines changed

doc/po/tutorial-container.md.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ msgstr ""
483483
#, no-wrap
484484
msgid ""
485485
"~~~\n"
486-
"impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {\n"
487-
" pub fn from_iterator(iterator: &mut T) -> ~[A] {\n"
486+
"impl<A> FromIterator<A> for ~[A] {\n"
487+
" pub fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {\n"
488488
" let (lower, _) = iterator.size_hint();\n"
489489
" let mut xs = with_capacity(lower);\n"
490490
" for x in iterator {\n"

doc/tutorial-container.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ implementing the `FromIterator` trait. For example, the implementation for
224224
vectors is as follows:
225225
226226
~~~
227-
impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
228-
pub fn from_iterator(iterator: &mut T) -> ~[A] {
227+
impl<A> FromIterator<A> for ~[A] {
228+
pub fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
229229
let (lower, _) = iterator.size_hint();
230230
let mut xs = with_capacity(lower);
231231
for x in iterator {

src/libextra/dlist.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,16 +573,16 @@ impl<A> DoubleEndedIterator<A> for MoveIterator<A> {
573573
fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
574574
}
575575

576-
impl<A, T: Iterator<A>> FromIterator<A, T> for DList<A> {
577-
fn from_iterator(iterator: &mut T) -> DList<A> {
576+
impl<A> FromIterator<A> for DList<A> {
577+
fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> DList<A> {
578578
let mut ret = DList::new();
579579
ret.extend(iterator);
580580
ret
581581
}
582582
}
583583

584-
impl<A, T: Iterator<A>> Extendable<A, T> for DList<A> {
585-
fn extend(&mut self, iterator: &mut T) {
584+
impl<A> Extendable<A> for DList<A> {
585+
fn extend<T: Iterator<A>>(&mut self, iterator: &mut T) {
586586
for elt in *iterator { self.push_back(elt); }
587587
}
588588
}
@@ -1163,4 +1163,3 @@ mod tests {
11631163
}
11641164
}
11651165
}
1166-

src/libextra/priority_queue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ impl<'self, T> Iterator<&'self T> for PriorityQueueIterator<'self, T> {
190190
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
191191
}
192192

193-
impl<T: Ord, Iter: Iterator<T>> FromIterator<T, Iter> for PriorityQueue<T> {
194-
fn from_iterator(iter: &mut Iter) -> PriorityQueue<T> {
193+
impl<T: Ord> FromIterator<T> for PriorityQueue<T> {
194+
fn from_iterator<Iter: Iterator<T>>(iter: &mut Iter) -> PriorityQueue<T> {
195195
let mut q = PriorityQueue::new();
196196
q.extend(iter);
197197

198198
q
199199
}
200200
}
201201

202-
impl<T: Ord, Iter: Iterator<T>> Extendable<T, Iter> for PriorityQueue<T> {
203-
fn extend(&mut self, iter: &mut Iter) {
202+
impl<T: Ord> Extendable<T> for PriorityQueue<T> {
203+
fn extend<Iter: Iterator<T>>(&mut self, iter: &mut Iter) {
204204
let (lower, _) = iter.size_hint();
205205

206206
let len = self.capacity();

src/libextra/ringbuf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,17 @@ impl<A: Eq> Eq for RingBuf<A> {
322322
}
323323
}
324324

325-
impl<A, T: Iterator<A>> FromIterator<A, T> for RingBuf<A> {
326-
fn from_iterator(iterator: &mut T) -> RingBuf<A> {
325+
impl<A> FromIterator<A> for RingBuf<A> {
326+
fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> RingBuf<A> {
327327
let (lower, _) = iterator.size_hint();
328328
let mut deq = RingBuf::with_capacity(lower);
329329
deq.extend(iterator);
330330
deq
331331
}
332332
}
333333

334-
impl<A, T: Iterator<A>> Extendable<A, T> for RingBuf<A> {
335-
fn extend(&mut self, iterator: &mut T) {
334+
impl<A> Extendable<A> for RingBuf<A> {
335+
fn extend<T: Iterator<A>>(&mut self, iterator: &mut T) {
336336
for elt in *iterator {
337337
self.push_back(elt);
338338
}

src/libextra/treemap.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -835,34 +835,34 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
835835
};
836836
}
837837

838-
impl<K: TotalOrd, V, T: Iterator<(K, V)>> FromIterator<(K, V), T> for TreeMap<K, V> {
839-
fn from_iterator(iter: &mut T) -> TreeMap<K, V> {
838+
impl<K: TotalOrd, V> FromIterator<(K, V)> for TreeMap<K, V> {
839+
fn from_iterator<T: Iterator<(K, V)>>(iter: &mut T) -> TreeMap<K, V> {
840840
let mut map = TreeMap::new();
841841
map.extend(iter);
842842
map
843843
}
844844
}
845845

846-
impl<K: TotalOrd, V, T: Iterator<(K, V)>> Extendable<(K, V), T> for TreeMap<K, V> {
846+
impl<K: TotalOrd, V> Extendable<(K, V)> for TreeMap<K, V> {
847847
#[inline]
848-
fn extend(&mut self, iter: &mut T) {
848+
fn extend<T: Iterator<(K, V)>>(&mut self, iter: &mut T) {
849849
for (k, v) in *iter {
850850
self.insert(k, v);
851851
}
852852
}
853853
}
854854

855-
impl<T: TotalOrd, Iter: Iterator<T>> FromIterator<T, Iter> for TreeSet<T> {
856-
fn from_iterator(iter: &mut Iter) -> TreeSet<T> {
855+
impl<T: TotalOrd> FromIterator<T> for TreeSet<T> {
856+
fn from_iterator<Iter: Iterator<T>>(iter: &mut Iter) -> TreeSet<T> {
857857
let mut set = TreeSet::new();
858858
set.extend(iter);
859859
set
860860
}
861861
}
862862

863-
impl<T: TotalOrd, Iter: Iterator<T>> Extendable<T, Iter> for TreeSet<T> {
863+
impl<T: TotalOrd> Extendable<T> for TreeSet<T> {
864864
#[inline]
865-
fn extend(&mut self, iter: &mut Iter) {
865+
fn extend<Iter: Iterator<T>>(&mut self, iter: &mut Iter) {
866866
for elem in *iter {
867867
self.insert(elem);
868868
}

src/libstd/hashmap.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,17 @@ impl<K> Iterator<K> for HashSetMoveIterator<K> {
605605
}
606606
}
607607

608-
impl<K: Eq + Hash, V, T: Iterator<(K, V)>> FromIterator<(K, V), T> for HashMap<K, V> {
609-
fn from_iterator(iter: &mut T) -> HashMap<K, V> {
608+
impl<K: Eq + Hash, V> FromIterator<(K, V)> for HashMap<K, V> {
609+
fn from_iterator<T: Iterator<(K, V)>>(iter: &mut T) -> HashMap<K, V> {
610610
let (lower, _) = iter.size_hint();
611611
let mut map = HashMap::with_capacity(lower);
612612
map.extend(iter);
613613
map
614614
}
615615
}
616616

617-
impl<K: Eq + Hash, V, T: Iterator<(K, V)>> Extendable<(K, V), T> for HashMap<K, V> {
618-
fn extend(&mut self, iter: &mut T) {
617+
impl<K: Eq + Hash, V> Extendable<(K, V)> for HashMap<K, V> {
618+
fn extend<T: Iterator<(K, V)>>(&mut self, iter: &mut T) {
619619
for (k, v) in *iter {
620620
self.insert(k, v);
621621
}
@@ -753,17 +753,17 @@ impl<T:Hash + Eq + Clone> Clone for HashSet<T> {
753753
}
754754
}
755755

756-
impl<K: Eq + Hash, T: Iterator<K>> FromIterator<K, T> for HashSet<K> {
757-
fn from_iterator(iter: &mut T) -> HashSet<K> {
756+
impl<K: Eq + Hash> FromIterator<K> for HashSet<K> {
757+
fn from_iterator<T: Iterator<K>>(iter: &mut T) -> HashSet<K> {
758758
let (lower, _) = iter.size_hint();
759759
let mut set = HashSet::with_capacity(lower);
760760
set.extend(iter);
761761
set
762762
}
763763
}
764764

765-
impl<K: Eq + Hash, T: Iterator<K>> Extendable<K, T> for HashSet<K> {
766-
fn extend(&mut self, iter: &mut T) {
765+
impl<K: Eq + Hash> Extendable<K> for HashSet<K> {
766+
fn extend<T: Iterator<K>>(&mut self, iter: &mut T) {
767767
for k in *iter {
768768
self.insert(k);
769769
}

src/libstd/iterator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ use clone::Clone;
2626
use uint;
2727

2828
/// Conversion from an `Iterator`
29-
pub trait FromIterator<A, T: Iterator<A>> {
29+
pub trait FromIterator<A> {
3030
/// Build a container with elements from an external iterator.
31-
fn from_iterator(iterator: &mut T) -> Self;
31+
fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> Self;
3232
}
3333

3434
/// A type growable from an `Iterator` implementation
35-
pub trait Extendable<A, T: Iterator<A>>: FromIterator<A, T> {
35+
pub trait Extendable<A>: FromIterator<A> {
3636
/// Extend a container with the elements yielded by an iterator
37-
fn extend(&mut self, iterator: &mut T);
37+
fn extend<T: Iterator<A>>(&mut self, iterator: &mut T);
3838
}
3939

4040
/// An interface for dealing with "external iterators". These types of iterators
@@ -353,7 +353,7 @@ pub trait Iterator<A> {
353353
/// assert!(a == b);
354354
/// ~~~
355355
#[inline]
356-
fn collect<B: FromIterator<A, Self>>(&mut self) -> B {
356+
fn collect<B: FromIterator<A>>(&mut self) -> B {
357357
FromIterator::from_iterator(self)
358358
}
359359

src/libstd/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,19 +2111,19 @@ impl Clone for @str {
21112111
}
21122112
}
21132113
2114-
impl<T: Iterator<char>> FromIterator<char, T> for ~str {
2114+
impl FromIterator<char> for ~str {
21152115
#[inline]
2116-
fn from_iterator(iterator: &mut T) -> ~str {
2116+
fn from_iterator<T: Iterator<char>>(iterator: &mut T) -> ~str {
21172117
let (lower, _) = iterator.size_hint();
21182118
let mut buf = with_capacity(lower);
21192119
buf.extend(iterator);
21202120
buf
21212121
}
21222122
}
21232123
2124-
impl<T: Iterator<char>> Extendable<char, T> for ~str {
2124+
impl Extendable<char> for ~str {
21252125
#[inline]
2126-
fn extend(&mut self, iterator: &mut T) {
2126+
fn extend<T: Iterator<char>>(&mut self, iterator: &mut T) {
21272127
let (lower, _) = iterator.size_hint();
21282128
let reserve = lower + self.len();
21292129
self.reserve_at_least(reserve);

src/libstd/trie.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ impl<T> TrieMap<T> {
205205
}
206206
}
207207

208-
impl<T, Iter: Iterator<(uint, T)>> FromIterator<(uint, T), Iter> for TrieMap<T> {
209-
fn from_iterator(iter: &mut Iter) -> TrieMap<T> {
208+
impl<T> FromIterator<(uint, T)> for TrieMap<T> {
209+
fn from_iterator<Iter: Iterator<(uint, T)>>(iter: &mut Iter) -> TrieMap<T> {
210210
let mut map = TrieMap::new();
211211
map.extend(iter);
212212
map
213213
}
214214
}
215215

216-
impl<T, Iter: Iterator<(uint, T)>> Extendable<(uint, T), Iter> for TrieMap<T> {
217-
fn extend(&mut self, iter: &mut Iter) {
216+
impl<T> Extendable<(uint, T)> for TrieMap<T> {
217+
fn extend<Iter: Iterator<(uint, T)>>(&mut self, iter: &mut Iter) {
218218
for (k, v) in *iter {
219219
self.insert(k, v);
220220
}
@@ -294,16 +294,16 @@ impl TrieSet {
294294
}
295295
}
296296

297-
impl<Iter: Iterator<uint>> FromIterator<uint, Iter> for TrieSet {
298-
fn from_iterator(iter: &mut Iter) -> TrieSet {
297+
impl FromIterator<uint> for TrieSet {
298+
fn from_iterator<Iter: Iterator<uint>>(iter: &mut Iter) -> TrieSet {
299299
let mut set = TrieSet::new();
300300
set.extend(iter);
301301
set
302302
}
303303
}
304304

305-
impl<Iter: Iterator<uint>> Extendable<uint, Iter> for TrieSet {
306-
fn extend(&mut self, iter: &mut Iter) {
305+
impl Extendable<uint> for TrieSet {
306+
fn extend<Iter: Iterator<uint>>(&mut self, iter: &mut Iter) {
307307
for elem in *iter {
308308
self.insert(elem);
309309
}

src/libstd/vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,8 @@ impl<T> Iterator<T> for MoveRevIterator<T> {
23162316
}
23172317
}
23182318

2319-
impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
2320-
fn from_iterator(iterator: &mut T) -> ~[A] {
2319+
impl<A> FromIterator<A> for ~[A] {
2320+
fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
23212321
let (lower, _) = iterator.size_hint();
23222322
let mut xs = with_capacity(lower);
23232323
for x in *iterator {
@@ -2327,8 +2327,8 @@ impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
23272327
}
23282328
}
23292329

2330-
impl<A, T: Iterator<A>> Extendable<A, T> for ~[A] {
2331-
fn extend(&mut self, iterator: &mut T) {
2330+
impl<A> Extendable<A> for ~[A] {
2331+
fn extend<T: Iterator<A>>(&mut self, iterator: &mut T) {
23322332
let (lower, _) = iterator.size_hint();
23332333
let len = self.len();
23342334
self.reserve(len + lower);

0 commit comments

Comments
 (0)