diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-08-13 23:08:14 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-08-15 01:10:45 +1000 |
| commit | 53487a02467ebe8816a3bdf03f16c3db958958a2 (patch) | |
| tree | 8d4a4aec4d1260579373f856ecfce70233538a71 /src/libstd | |
| parent | 58021be45441efc6bf0a10eb58a407f74e9eaed0 (diff) | |
| download | rust-53487a02467ebe8816a3bdf03f16c3db958958a2.tar.gz rust-53487a02467ebe8816a3bdf03f16c3db958958a2.zip | |
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, ...) { ... }
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/hashmap.rs | 16 | ||||
| -rw-r--r-- | src/libstd/iterator.rs | 10 | ||||
| -rw-r--r-- | src/libstd/str.rs | 8 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 16 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 8 |
5 files changed, 29 insertions, 29 deletions
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 @@ impl<K> Iterator<K> for HashSetMoveIterator<K> { } } -impl<K: Eq + Hash, V, T: Iterator<(K, V)>> FromIterator<(K, V), T> for HashMap<K, V> { - fn from_iterator(iter: &mut T) -> HashMap<K, V> { +impl<K: Eq + Hash, V> FromIterator<(K, V)> for HashMap<K, V> { + fn from_iterator<T: Iterator<(K, V)>>(iter: &mut T) -> HashMap<K, V> { let (lower, _) = iter.size_hint(); let mut map = HashMap::with_capacity(lower); map.extend(iter); @@ -614,8 +614,8 @@ impl<K: Eq + Hash, V, T: Iterator<(K, V)>> FromIterator<(K, V), T> for HashMap<K } } -impl<K: Eq + Hash, V, T: Iterator<(K, V)>> Extendable<(K, V), T> for HashMap<K, V> { - fn extend(&mut self, iter: &mut T) { +impl<K: Eq + Hash, V> Extendable<(K, V)> for HashMap<K, V> { + fn extend<T: Iterator<(K, V)>>(&mut self, iter: &mut T) { for (k, v) in *iter { self.insert(k, v); } @@ -753,8 +753,8 @@ impl<T:Hash + Eq + Clone> Clone for HashSet<T> { } } -impl<K: Eq + Hash, T: Iterator<K>> FromIterator<K, T> for HashSet<K> { - fn from_iterator(iter: &mut T) -> HashSet<K> { +impl<K: Eq + Hash> FromIterator<K> for HashSet<K> { + fn from_iterator<T: Iterator<K>>(iter: &mut T) -> HashSet<K> { let (lower, _) = iter.size_hint(); let mut set = HashSet::with_capacity(lower); set.extend(iter); @@ -762,8 +762,8 @@ impl<K: Eq + Hash, T: Iterator<K>> FromIterator<K, T> for HashSet<K> { } } -impl<K: Eq + Hash, T: Iterator<K>> Extendable<K, T> for HashSet<K> { - fn extend(&mut self, iter: &mut T) { +impl<K: Eq + Hash> Extendable<K> for HashSet<K> { + fn extend<T: Iterator<K>>(&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 clone::Clone; use uint; /// Conversion from an `Iterator` -pub trait FromIterator<A, T: Iterator<A>> { +pub trait FromIterator<A> { /// Build a container with elements from an external iterator. - fn from_iterator(iterator: &mut T) -> Self; + fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> Self; } /// A type growable from an `Iterator` implementation -pub trait Extendable<A, T: Iterator<A>>: FromIterator<A, T> { +pub trait Extendable<A>: FromIterator<A> { /// Extend a container with the elements yielded by an iterator - fn extend(&mut self, iterator: &mut T); + fn extend<T: Iterator<A>>(&mut self, iterator: &mut T); } /// An interface for dealing with "external iterators". These types of iterators @@ -353,7 +353,7 @@ pub trait Iterator<A> { /// assert!(a == b); /// ~~~ #[inline] - fn collect<B: FromIterator<A, Self>>(&mut self) -> B { + fn collect<B: FromIterator<A>>(&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 @@ impl Clone for @str { } } -impl<T: Iterator<char>> FromIterator<char, T> for ~str { +impl FromIterator<char> for ~str { #[inline] - fn from_iterator(iterator: &mut T) -> ~str { + fn from_iterator<T: Iterator<char>>(iterator: &mut T) -> ~str { let (lower, _) = iterator.size_hint(); let mut buf = with_capacity(lower); buf.extend(iterator); @@ -2121,9 +2121,9 @@ impl<T: Iterator<char>> FromIterator<char, T> for ~str { } } -impl<T: Iterator<char>> Extendable<char, T> for ~str { +impl Extendable<char> for ~str { #[inline] - fn extend(&mut self, iterator: &mut T) { + fn extend<T: Iterator<char>>(&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 @@ impl<T> TrieMap<T> { } } -impl<T, Iter: Iterator<(uint, T)>> FromIterator<(uint, T), Iter> for TrieMap<T> { - fn from_iterator(iter: &mut Iter) -> TrieMap<T> { +impl<T> FromIterator<(uint, T)> for TrieMap<T> { + fn from_iterator<Iter: Iterator<(uint, T)>>(iter: &mut Iter) -> TrieMap<T> { let mut map = TrieMap::new(); map.extend(iter); map } } -impl<T, Iter: Iterator<(uint, T)>> Extendable<(uint, T), Iter> for TrieMap<T> { - fn extend(&mut self, iter: &mut Iter) { +impl<T> Extendable<(uint, T)> for TrieMap<T> { + fn extend<Iter: Iterator<(uint, T)>>(&mut self, iter: &mut Iter) { for (k, v) in *iter { self.insert(k, v); } @@ -294,16 +294,16 @@ impl TrieSet { } } -impl<Iter: Iterator<uint>> FromIterator<uint, Iter> for TrieSet { - fn from_iterator(iter: &mut Iter) -> TrieSet { +impl FromIterator<uint> for TrieSet { + fn from_iterator<Iter: Iterator<uint>>(iter: &mut Iter) -> TrieSet { let mut set = TrieSet::new(); set.extend(iter); set } } -impl<Iter: Iterator<uint>> Extendable<uint, Iter> for TrieSet { - fn extend(&mut self, iter: &mut Iter) { +impl Extendable<uint> for TrieSet { + fn extend<Iter: Iterator<uint>>(&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 @@ impl<T> Iterator<T> for MoveRevIterator<T> { } } -impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] { - fn from_iterator(iterator: &mut T) -> ~[A] { +impl<A> FromIterator<A> for ~[A] { + fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] { let (lower, _) = iterator.size_hint(); let mut xs = with_capacity(lower); for x in *iterator { @@ -2327,8 +2327,8 @@ impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] { } } -impl<A, T: Iterator<A>> Extendable<A, T> for ~[A] { - fn extend(&mut self, iterator: &mut T) { +impl<A> Extendable<A> for ~[A] { + fn extend<T: Iterator<A>>(&mut self, iterator: &mut T) { let (lower, _) = iterator.size_hint(); let len = self.len(); self.reserve(len + lower); |
