diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-17 20:48:07 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 08:26:20 -0800 |
| commit | f83e23ad7c464c242c2d7ace7212d323980b2bca (patch) | |
| tree | 4af495be32288f7af75d660173a19e412c9a29d8 /src/libserialize | |
| parent | dfc5c0f1e8799f47f9033bdcc8a7cd8a217620a5 (diff) | |
| download | rust-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/libserialize')
| -rw-r--r-- | src/libserialize/collection_impls.rs | 76 | ||||
| -rw-r--r-- | src/libserialize/lib.rs | 1 |
2 files changed, 75 insertions, 2 deletions
diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index f81edca8371..7176ad7f88d 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -12,7 +12,8 @@ use std::usize; use std::default::Default; -use std::hash::{Hash, Hasher}; +use std::hash::Hash; +#[cfg(stage0)] use std::hash::Hasher; use std::collections::hash_state::HashState; use {Decodable, Encodable, Decoder, Encoder}; @@ -157,6 +158,7 @@ impl< } } +#[cfg(stage0)] impl<K, V, S> Encodable for HashMap<K, V, S> where K: Encodable + Hash< <S as HashState>::Hasher> + Eq, V: Encodable, @@ -175,7 +177,26 @@ impl<K, V, S> Encodable for HashMap<K, V, S> }) } } +#[cfg(not(stage0))] +impl<K, V, S> Encodable for HashMap<K, V, S> + where K: Encodable + Hash + Eq, + V: Encodable, + S: HashState, +{ + fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> { + e.emit_map(self.len(), |e| { + let mut i = 0; + for (key, val) in self { + try!(e.emit_map_elt_key(i, |e| key.encode(e))); + try!(e.emit_map_elt_val(i, |e| val.encode(e))); + i += 1; + } + Ok(()) + }) + } +} +#[cfg(stage0)] impl<K, V, S> Decodable for HashMap<K, V, S> where K: Decodable + Hash< <S as HashState>::Hasher> + Eq, V: Decodable, @@ -195,7 +216,27 @@ impl<K, V, S> Decodable for HashMap<K, V, S> }) } } +#[cfg(not(stage0))] +impl<K, V, S> Decodable for HashMap<K, V, S> + where K: Decodable + Hash + Eq, + V: Decodable, + S: HashState + 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); + 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))); + map.insert(key, val); + } + Ok(map) + }) + } +} +#[cfg(stage0)] impl<T, S> Encodable for HashSet<T, S> where T: Encodable + Hash< <S as HashState>::Hasher> + Eq, S: HashState, @@ -212,7 +253,24 @@ impl<T, S> Encodable for HashSet<T, S> }) } } +#[cfg(not(stage0))] +impl<T, S> Encodable for HashSet<T, S> + where T: Encodable + Hash + Eq, + S: HashState, +{ + fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> { + s.emit_seq(self.len(), |s| { + let mut i = 0; + for e in self { + try!(s.emit_seq_elt(i, |s| e.encode(s))); + i += 1; + } + Ok(()) + }) + } +} +#[cfg(stage0)] impl<T, S> Decodable for HashSet<T, S> where T: Decodable + Hash< <S as HashState>::Hasher> + Eq, S: HashState + Default, @@ -229,6 +287,22 @@ impl<T, S> Decodable for HashSet<T, S> }) } } +#[cfg(not(stage0))] +impl<T, S> Decodable for HashSet<T, S> + where T: Decodable + Hash + Eq, + S: HashState + 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); + for i in 0..len { + set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); + } + Ok(set) + }) + } +} impl<V: Encodable> Encodable for VecMap<V> { fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 853da598ab5..d476fd72abc 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -31,7 +31,6 @@ Core encoding and decoding interfaces. #![feature(int_uint)] #![feature(old_io)] #![feature(old_path)] -#![feature(hash)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(std_misc)] |
