about summary refs log tree commit diff
path: root/src/libcollections/vec_map.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-02-17 20:48:07 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-02-18 08:26:20 -0800
commitf83e23ad7c464c242c2d7ace7212d323980b2bca (patch)
tree4af495be32288f7af75d660173a19e412c9a29d8 /src/libcollections/vec_map.rs
parentdfc5c0f1e8799f47f9033bdcc8a7cd8a217620a5 (diff)
downloadrust-f83e23ad7c464c242c2d7ace7212d323980b2bca.tar.gz
rust-f83e23ad7c464c242c2d7ace7212d323980b2bca.zip
std: Stabilize the `hash` module
This commit is an implementation of [RFC 823][rfc] which is another pass over
the `std::hash` module for stabilization. The contents of the module were not
entirely marked stable, but some portions which remained quite similar to the
previous incarnation are now marked `#[stable]`. Specifically:

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0823-hash-simplification.md

* `std::hash` is now stable (the name)
* `Hash` is now stable
* `Hash::hash` is now stable
* `Hasher` is now stable
* `SipHasher` is now stable
* `SipHasher::new` and `new_with_keys` are now stable
* `Hasher for SipHasher` is now stable
* Many `Hash` implementations are now stable

All other portions of the `hash` module remain `#[unstable]` as they are less
commonly used and were recently redesigned.

This commit is a breaking change due to the modifications to the `std::hash` API
and more details can be found on the [RFC][rfc].

Closes #22467
[breaking-change]
Diffstat (limited to 'src/libcollections/vec_map.rs')
-rw-r--r--src/libcollections/vec_map.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs
index 82ccfd0614f..c271cb052ab 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`.