@@ -255,10 +255,44 @@ pub trait BuildHasher {
255255 fn build_hasher ( & self ) -> Self :: Hasher ;
256256}
257257
258- /// A structure which implements `BuildHasher` for all `Hasher` types which also
259- /// implement `Default`.
258+ /// The `BuildHasherDefault` structure is used in scenarios where one has a
259+ /// type that implements [`Hasher`] and [`Default`], but needs that type to
260+ /// implement [`BuildHasher`].
260261///
261- /// This struct is 0-sized and does not need construction.
262+ /// This structure is zero-sized and does not need construction.
263+ ///
264+ /// # Examples
265+ ///
266+ /// Using `BuildHasherDefault` to specify a custom [`BuildHasher`] for
267+ /// [`HashMap`]:
268+ ///
269+ /// ```
270+ /// use std::collections::HashMap;
271+ /// use std::hash::{BuildHasherDefault, Hasher};
272+ ///
273+ /// #[derive(Default)]
274+ /// struct MyHasher;
275+ ///
276+ /// impl Hasher for MyHasher {
277+ /// fn write(&mut self, bytes: &[u8]) {
278+ /// // Your hashing algorithm goes here!
279+ /// unimplemented!()
280+ /// }
281+ ///
282+ /// fn finish(&self) -> u64 {
283+ /// // Your hashing algorithm goes here!
284+ /// unimplemented!()
285+ /// }
286+ /// }
287+ ///
288+ /// type MyBuildHasher = BuildHasherDefault<SomeHasher>;
289+ ///
290+ /// let hash_map = HashMap::<u32, u32, SomeBuidHasher>::default();
291+ /// ```
292+ ///
293+ /// [`BuildHasher`]: trait.BuildHasher.html
294+ /// [`Default`]: ../default/trait.Default.html
295+ /// [`Hasher`]: trait.Hasher.html
262296#[ stable( since = "1.7.0" , feature = "build_hasher" ) ]
263297pub struct BuildHasherDefault < H > ( marker:: PhantomData < H > ) ;
264298
0 commit comments