about summary refs log tree commit diff
path: root/src/libserialize
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-01-21 10:28:39 -0800
committerAlex Crichton <alex@alexcrichton.com>2016-01-26 08:39:07 -0800
commit1fa0be2bc038e0575a601ba0273cd83d91d064f2 (patch)
tree7f73d02c1762d6958e343176469b934b46ef31cc /src/libserialize
parent670f5b06e47d847b3fc8c61392a65202f1d3dfa2 (diff)
downloadrust-1fa0be2bc038e0575a601ba0273cd83d91d064f2.tar.gz
rust-1fa0be2bc038e0575a601ba0273cd83d91d064f2.zip
std: Stabilize custom hasher support in HashMap
This commit implements the stabilization of the custom hasher support intended
for 1.7 but left out due to some last-minute questions that needed some
decisions. A summary of the actions done in this PR are:

Stable

* `std::hash::BuildHasher`
* `BuildHasher::Hasher`
* `BuildHasher::build_hasher`
* `std::hash::BuildHasherDefault`
* `HashMap::with_hasher`
* `HashMap::with_capacity_and_hasher`
* `HashSet::with_hasher`
* `HashSet::with_capacity_and_hasher`
* `std::collections::hash_map::RandomState`
* `RandomState::new`

Deprecated

* `std::collections::hash_state`
* `std::collections::hash_state::HashState` - this trait was also moved into
  `std::hash` with a reexport here to ensure that we can have a blanket impl to
  prevent immediate breakage on nightly. Note that this is unstable in both
  location.
* `HashMap::with_hash_state` - renamed
* `HashMap::with_capacity_and_hash_state` - renamed
* `HashSet::with_hash_state` - renamed
* `HashSet::with_capacity_and_hash_state` - renamed

Closes #27713
Diffstat (limited to 'src/libserialize')
-rw-r--r--src/libserialize/collection_impls.rs15
-rw-r--r--src/libserialize/lib.rs1
2 files changed, 7 insertions, 9 deletions
diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs
index e21307cc752..804e1af19ab 100644
--- a/src/libserialize/collection_impls.rs
+++ b/src/libserialize/collection_impls.rs
@@ -10,8 +10,7 @@
 
 //! Implementations of serialization for structures found in libcollections
 
-use std::hash::Hash;
-use std::collections::hash_state::HashState;
+use std::hash::{Hash, BuildHasher};
 use std::mem;
 
 use {Decodable, Encodable, Decoder, Encoder};
@@ -159,7 +158,7 @@ impl<
 impl<K, V, S> Encodable for HashMap<K, V, S>
     where K: Encodable + Hash + Eq,
           V: Encodable,
-          S: HashState,
+          S: BuildHasher,
 {
     fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
         e.emit_map(self.len(), |e| {
@@ -177,12 +176,12 @@ impl<K, V, S> Encodable for HashMap<K, V, S>
 impl<K, V, S> Decodable for HashMap<K, V, S>
     where K: Decodable + Hash + Eq,
           V: Decodable,
-          S: HashState + Default,
+          S: BuildHasher + Default,
 {
     fn decode<D: Decoder>(d: &mut D) -> Result<HashMap<K, V, S>, D::Error> {
         d.read_map(|d, len| {
             let state = Default::default();
-            let mut map = HashMap::with_capacity_and_hash_state(len, state);
+            let mut map = HashMap::with_capacity_and_hasher(len, state);
             for i in 0..len {
                 let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d)));
                 let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d)));
@@ -195,7 +194,7 @@ impl<K, V, S> Decodable for HashMap<K, V, S>
 
 impl<T, S> Encodable for HashSet<T, S>
     where T: Encodable + Hash + Eq,
-          S: HashState,
+          S: BuildHasher,
 {
     fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
         s.emit_seq(self.len(), |s| {
@@ -211,12 +210,12 @@ impl<T, S> Encodable for HashSet<T, S>
 
 impl<T, S> Decodable for HashSet<T, S>
     where T: Decodable + Hash + Eq,
-          S: HashState + Default,
+          S: BuildHasher + Default,
 {
     fn decode<D: Decoder>(d: &mut D) -> Result<HashSet<T, S>, D::Error> {
         d.read_seq(|d, len| {
             let state = Default::default();
-            let mut set = HashSet::with_capacity_and_hash_state(len, state);
+            let mut set = HashSet::with_capacity_and_hasher(len, state);
             for i in 0..len {
                 set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
             }
diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs
index 910600d91e4..8bb596c8bb2 100644
--- a/src/libserialize/lib.rs
+++ b/src/libserialize/lib.rs
@@ -29,7 +29,6 @@ Core encoding and decoding interfaces.
 #![feature(box_syntax)]
 #![feature(collections)]
 #![feature(enumset)]
-#![feature(hashmap_hasher)]
 #![feature(rustc_private)]
 #![feature(staged_api)]
 #![feature(str_char)]