diff options
Diffstat (limited to 'src/libcollections/vec_map.rs')
| -rw-r--r-- | src/libcollections/vec_map.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 82ccfd0614f..54589a31423 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -20,7 +20,8 @@ use core::prelude::*; use core::cmp::Ordering; use core::default::Default; use core::fmt; -use core::hash::{Hash, Writer, Hasher}; +use core::hash::{Hash, Hasher}; +#[cfg(stage0)] use core::hash::Writer; use core::iter::{Enumerate, FilterMap, Map, FromIterator, IntoIterator}; use core::iter; use core::mem::replace; @@ -99,6 +100,7 @@ impl<V> Default for VecMap<V> { fn default() -> VecMap<V> { VecMap::new() } } +#[stable(feature = "rust1", since = "1.0.0")] impl<V:Clone> Clone for VecMap<V> { #[inline] fn clone(&self) -> VecMap<V> { @@ -111,6 +113,7 @@ impl<V:Clone> Clone for VecMap<V> { } } +#[cfg(stage0)] impl<S: Writer + Hasher, V: Hash<S>> Hash<S> for VecMap<V> { fn hash(&self, state: &mut S) { // In order to not traverse the `VecMap` twice, count the elements @@ -123,6 +126,20 @@ impl<S: Writer + Hasher, V: Hash<S>> Hash<S> for VecMap<V> { count.hash(state); } } +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(stage0))] +impl<V: Hash> Hash for VecMap<V> { + fn hash<H: Hasher>(&self, state: &mut H) { + // In order to not traverse the `VecMap` twice, count the elements + // during iteration. + let mut count: usize = 0; + for elt in self { + elt.hash(state); + count += 1; + } + count.hash(state); + } +} impl<V> VecMap<V> { /// Creates an empty `VecMap`. @@ -661,7 +678,7 @@ impl<V: fmt::Debug> fmt::Debug for VecMap<V> { #[stable(feature = "rust1", since = "1.0.0")] impl<V> FromIterator<(usize, V)> for VecMap<V> { - fn from_iter<Iter: Iterator<Item=(usize, V)>>(iter: Iter) -> VecMap<V> { + fn from_iter<I: IntoIterator<Item=(usize, V)>>(iter: I) -> VecMap<V> { let mut map = VecMap::new(); map.extend(iter); map @@ -700,7 +717,7 @@ impl<'a, T> IntoIterator for &'a mut VecMap<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<V> Extend<(usize, V)> for VecMap<V> { - fn extend<Iter: Iterator<Item=(usize, V)>>(&mut self, iter: Iter) { + fn extend<I: IntoIterator<Item=(usize, V)>>(&mut self, iter: I) { for (k, v) in iter { self.insert(k, v); } @@ -859,7 +876,7 @@ pub struct IntoIter<V> { } #[unstable(feature = "collections")] -pub struct Drain<'a, V> { +pub struct Drain<'a, V:'a> { iter: FilterMap< Enumerate<vec::Drain<'a, Option<V>>>, fn((usize, Option<V>)) -> Option<(usize, V)>> |
