]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/hash/mod.rs
std: Clean out deprecated APIs
[rust.git] / src / libcore / hash / mod.rs
index 0781dd3b7742f9d54611f78aae1705a83e65e8da..3c219692bc48de8b5981937d283f41198a93b169 100644 (file)
@@ -73,6 +73,7 @@
 
 use prelude::v1::*;
 
+use marker;
 use mem;
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -190,6 +191,53 @@ fn write_isize(&mut self, i: isize) {
     }
 }
 
+/// A `BuildHasher` is typically used as a factory for instances of `Hasher`
+/// which a `HashMap` can then use to hash keys independently.
+///
+/// Note that for each instance of `BuildHasher`, the created hashers should be
+/// identical. That is, if the same stream of bytes is fed into each hasher, the
+/// same output will also be generated.
+#[stable(since = "1.7.0", feature = "build_hasher")]
+pub trait BuildHasher {
+    /// Type of the hasher that will be created.
+    #[stable(since = "1.7.0", feature = "build_hasher")]
+    type Hasher: Hasher;
+
+    /// Creates a new hasher.
+    #[stable(since = "1.7.0", feature = "build_hasher")]
+    fn build_hasher(&self) -> Self::Hasher;
+}
+
+/// A structure which implements `BuildHasher` for all `Hasher` types which also
+/// implement `Default`.
+///
+/// This struct is 0-sized and does not need construction.
+#[stable(since = "1.7.0", feature = "build_hasher")]
+pub struct BuildHasherDefault<H>(marker::PhantomData<H>);
+
+#[stable(since = "1.7.0", feature = "build_hasher")]
+impl<H: Default + Hasher> BuildHasher for BuildHasherDefault<H> {
+    type Hasher = H;
+
+    fn build_hasher(&self) -> H {
+        H::default()
+    }
+}
+
+#[stable(since = "1.7.0", feature = "build_hasher")]
+impl<H> Clone for BuildHasherDefault<H> {
+    fn clone(&self) -> BuildHasherDefault<H> {
+        BuildHasherDefault(marker::PhantomData)
+    }
+}
+
+#[stable(since = "1.7.0", feature = "build_hasher")]
+impl<H> Default for BuildHasherDefault<H> {
+    fn default() -> BuildHasherDefault<H> {
+        BuildHasherDefault(marker::PhantomData)
+    }
+}
+
 //////////////////////////////////////////////////////////////////////////////
 
 mod impls {