From 53487a02467ebe8816a3bdf03f16c3db958958a2 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 13 Aug 2013 23:08:14 +1000 Subject: [PATCH] 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 to a function that filled it either from a Range or a Map, one needs to write something like: fn foo> + Extendable>> (e: &mut E, ...) { ... } since using a generic, i.e. `foo, I: Iterator>` 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: &mut E, ...) { ... } --- doc/po/tutorial-container.md.pot | 4 ++-- doc/tutorial-container.md | 4 ++-- src/libextra/dlist.rs | 9 ++++----- src/libextra/priority_queue.rs | 8 ++++---- src/libextra/ringbuf.rs | 8 ++++---- src/libextra/treemap.rs | 16 ++++++++-------- src/libstd/hashmap.rs | 16 ++++++++-------- src/libstd/iterator.rs | 10 +++++----- src/libstd/str.rs | 8 ++++---- src/libstd/trie.rs | 16 ++++++++-------- src/libstd/vec.rs | 8 ++++---- 11 files changed, 53 insertions(+), 54 deletions(-) diff --git a/doc/po/tutorial-container.md.pot b/doc/po/tutorial-container.md.pot index 3435a51dbef..9c56b93f80b 100644 --- a/doc/po/tutorial-container.md.pot +++ b/doc/po/tutorial-container.md.pot @@ -483,8 +483,8 @@ msgstr "" #, no-wrap msgid "" "~~~\n" -"impl> FromIterator for ~[A] {\n" -" pub fn from_iterator(iterator: &mut T) -> ~[A] {\n" +"impl FromIterator for ~[A] {\n" +" pub fn from_iterator>(iterator: &mut T) -> ~[A] {\n" " let (lower, _) = iterator.size_hint();\n" " let mut xs = with_capacity(lower);\n" " for x in iterator {\n" diff --git a/doc/tutorial-container.md b/doc/tutorial-container.md index 19cd58bd3b4..8d0e8e200d0 100644 --- a/doc/tutorial-container.md +++ b/doc/tutorial-container.md @@ -224,8 +224,8 @@ implementing the `FromIterator` trait. For example, the implementation for vectors is as follows: ~~~ -impl> FromIterator for ~[A] { - pub fn from_iterator(iterator: &mut T) -> ~[A] { +impl FromIterator for ~[A] { + pub fn from_iterator>(iterator: &mut T) -> ~[A] { let (lower, _) = iterator.size_hint(); let mut xs = with_capacity(lower); for x in iterator { diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 788ed726d0f..076e86dd5b0 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -573,16 +573,16 @@ impl DoubleEndedIterator for MoveIterator { fn next_back(&mut self) -> Option { self.list.pop_back() } } -impl> FromIterator for DList { - fn from_iterator(iterator: &mut T) -> DList { +impl FromIterator for DList { + fn from_iterator>(iterator: &mut T) -> DList { let mut ret = DList::new(); ret.extend(iterator); ret } } -impl> Extendable for DList { - fn extend(&mut self, iterator: &mut T) { +impl Extendable for DList { + fn extend>(&mut self, iterator: &mut T) { for elt in *iterator { self.push_back(elt); } } } @@ -1163,4 +1163,3 @@ fn bench_iter_mut_rev(b: &mut test::BenchHarness) { } } } - diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index 4b94219b30d..4f0fed5fccf 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -190,8 +190,8 @@ fn next(&mut self) -> Option<(&'self T)> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -impl> FromIterator for PriorityQueue { - fn from_iterator(iter: &mut Iter) -> PriorityQueue { +impl FromIterator for PriorityQueue { + fn from_iterator>(iter: &mut Iter) -> PriorityQueue { let mut q = PriorityQueue::new(); q.extend(iter); @@ -199,8 +199,8 @@ fn from_iterator(iter: &mut Iter) -> PriorityQueue { } } -impl> Extendable for PriorityQueue { - fn extend(&mut self, iter: &mut Iter) { +impl Extendable for PriorityQueue { + fn extend>(&mut self, iter: &mut Iter) { let (lower, _) = iter.size_hint(); let len = self.capacity(); diff --git a/src/libextra/ringbuf.rs b/src/libextra/ringbuf.rs index bb9ac74bc77..a38cb580c50 100644 --- a/src/libextra/ringbuf.rs +++ b/src/libextra/ringbuf.rs @@ -322,8 +322,8 @@ fn ne(&self, other: &RingBuf) -> bool { } } -impl> FromIterator for RingBuf { - fn from_iterator(iterator: &mut T) -> RingBuf { +impl FromIterator for RingBuf { + fn from_iterator>(iterator: &mut T) -> RingBuf { let (lower, _) = iterator.size_hint(); let mut deq = RingBuf::with_capacity(lower); deq.extend(iterator); @@ -331,8 +331,8 @@ fn from_iterator(iterator: &mut T) -> RingBuf { } } -impl> Extendable for RingBuf { - fn extend(&mut self, iterator: &mut T) { +impl Extendable for RingBuf { + fn extend>(&mut self, iterator: &mut T) { for elt in *iterator { self.push_back(elt); } diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 486a7dab5c1..118754ec028 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -835,34 +835,34 @@ fn heir_swap(node: &mut ~TreeNode, }; } -impl> FromIterator<(K, V), T> for TreeMap { - fn from_iterator(iter: &mut T) -> TreeMap { +impl FromIterator<(K, V)> for TreeMap { + fn from_iterator>(iter: &mut T) -> TreeMap { let mut map = TreeMap::new(); map.extend(iter); map } } -impl> Extendable<(K, V), T> for TreeMap { +impl Extendable<(K, V)> for TreeMap { #[inline] - fn extend(&mut self, iter: &mut T) { + fn extend>(&mut self, iter: &mut T) { for (k, v) in *iter { self.insert(k, v); } } } -impl> FromIterator for TreeSet { - fn from_iterator(iter: &mut Iter) -> TreeSet { +impl FromIterator for TreeSet { + fn from_iterator>(iter: &mut Iter) -> TreeSet { let mut set = TreeSet::new(); set.extend(iter); set } } -impl> Extendable for TreeSet { +impl Extendable for TreeSet { #[inline] - fn extend(&mut self, iter: &mut Iter) { + fn extend>(&mut self, iter: &mut Iter) { for elem in *iter { self.insert(elem); } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 201d4692694..50e59cf438d 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -605,8 +605,8 @@ fn next(&mut self) -> Option { } } -impl> FromIterator<(K, V), T> for HashMap { - fn from_iterator(iter: &mut T) -> HashMap { +impl FromIterator<(K, V)> for HashMap { + fn from_iterator>(iter: &mut T) -> HashMap { let (lower, _) = iter.size_hint(); let mut map = HashMap::with_capacity(lower); map.extend(iter); @@ -614,8 +614,8 @@ fn from_iterator(iter: &mut T) -> HashMap { } } -impl> Extendable<(K, V), T> for HashMap { - fn extend(&mut self, iter: &mut T) { +impl Extendable<(K, V)> for HashMap { + fn extend>(&mut self, iter: &mut T) { for (k, v) in *iter { self.insert(k, v); } @@ -753,8 +753,8 @@ fn clone(&self) -> HashSet { } } -impl> FromIterator for HashSet { - fn from_iterator(iter: &mut T) -> HashSet { +impl FromIterator for HashSet { + fn from_iterator>(iter: &mut T) -> HashSet { let (lower, _) = iter.size_hint(); let mut set = HashSet::with_capacity(lower); set.extend(iter); @@ -762,8 +762,8 @@ fn from_iterator(iter: &mut T) -> HashSet { } } -impl> Extendable for HashSet { - fn extend(&mut self, iter: &mut T) { +impl Extendable for HashSet { + fn extend>(&mut self, iter: &mut T) { for k in *iter { self.insert(k); } diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index bd89c271a36..1a5e364542b 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -26,15 +26,15 @@ use uint; /// Conversion from an `Iterator` -pub trait FromIterator> { +pub trait FromIterator { /// Build a container with elements from an external iterator. - fn from_iterator(iterator: &mut T) -> Self; + fn from_iterator>(iterator: &mut T) -> Self; } /// A type growable from an `Iterator` implementation -pub trait Extendable>: FromIterator { +pub trait Extendable: FromIterator { /// Extend a container with the elements yielded by an iterator - fn extend(&mut self, iterator: &mut T); + fn extend>(&mut self, iterator: &mut T); } /// An interface for dealing with "external iterators". These types of iterators @@ -353,7 +353,7 @@ fn advance(&mut self, f: &fn(A) -> bool) -> bool { /// assert!(a == b); /// ~~~ #[inline] - fn collect>(&mut self) -> B { + fn collect>(&mut self) -> B { FromIterator::from_iterator(self) } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index b8e61536941..bc9d427676c 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2111,9 +2111,9 @@ fn clone(&self) -> @str { } } -impl> FromIterator for ~str { +impl FromIterator for ~str { #[inline] - fn from_iterator(iterator: &mut T) -> ~str { + fn from_iterator>(iterator: &mut T) -> ~str { let (lower, _) = iterator.size_hint(); let mut buf = with_capacity(lower); buf.extend(iterator); @@ -2121,9 +2121,9 @@ fn from_iterator(iterator: &mut T) -> ~str { } } -impl> Extendable for ~str { +impl Extendable for ~str { #[inline] - fn extend(&mut self, iterator: &mut T) { + fn extend>(&mut self, iterator: &mut T) { let (lower, _) = iterator.size_hint(); let reserve = lower + self.len(); self.reserve_at_least(reserve); diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index da1fb9abaee..f5c7b719c4f 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -205,16 +205,16 @@ pub fn upper_bound_iter<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> { } } -impl> FromIterator<(uint, T), Iter> for TrieMap { - fn from_iterator(iter: &mut Iter) -> TrieMap { +impl FromIterator<(uint, T)> for TrieMap { + fn from_iterator>(iter: &mut Iter) -> TrieMap { let mut map = TrieMap::new(); map.extend(iter); map } } -impl> Extendable<(uint, T), Iter> for TrieMap { - fn extend(&mut self, iter: &mut Iter) { +impl Extendable<(uint, T)> for TrieMap { + fn extend>(&mut self, iter: &mut Iter) { for (k, v) in *iter { self.insert(k, v); } @@ -294,16 +294,16 @@ pub fn upper_bound_iter<'a>(&'a self, val: uint) -> TrieSetIterator<'a> { } } -impl> FromIterator for TrieSet { - fn from_iterator(iter: &mut Iter) -> TrieSet { +impl FromIterator for TrieSet { + fn from_iterator>(iter: &mut Iter) -> TrieSet { let mut set = TrieSet::new(); set.extend(iter); set } } -impl> Extendable for TrieSet { - fn extend(&mut self, iter: &mut Iter) { +impl Extendable for TrieSet { + fn extend>(&mut self, iter: &mut Iter) { for elem in *iter { self.insert(elem); } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 27e09d85479..1996a9f970d 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2316,8 +2316,8 @@ fn next(&mut self) -> Option { } } -impl> FromIterator for ~[A] { - fn from_iterator(iterator: &mut T) -> ~[A] { +impl FromIterator for ~[A] { + fn from_iterator>(iterator: &mut T) -> ~[A] { let (lower, _) = iterator.size_hint(); let mut xs = with_capacity(lower); for x in *iterator { @@ -2327,8 +2327,8 @@ fn from_iterator(iterator: &mut T) -> ~[A] { } } -impl> Extendable for ~[A] { - fn extend(&mut self, iterator: &mut T) { +impl Extendable for ~[A] { + fn extend>(&mut self, iterator: &mut T) { let (lower, _) = iterator.size_hint(); let len = self.len(); self.reserve(len + lower);