| 
16 | 16 | //! Since it extends `core::hash::Hasher`, `Hasher` can be used with any type which implements the  | 
17 | 17 | //! standard `Hash` trait.  | 
18 | 18 | //!  | 
19 |  | -//! This crate also adds a version of `BuildHasherDefault` with a const constructor, to work around  | 
20 |  | -//! the `core` version's lack of one.  | 
21 |  | -//!  | 
22 | 19 | //! [`core::hash`]: https://doc.rust-lang.org/std/hash/index.html  | 
23 | 20 | //! [`finish32`]: crate::Hasher::finish32  | 
24 | 21 | //!  | 
 | 
37 | 34 | //!  | 
38 | 35 | //! The trait bound `H: hash32::Hasher` is *more* restrictive as it only accepts 32-bit hashers.  | 
39 | 36 | //!  | 
40 |  | -//! The `BuildHasherDefault<H>` type implements the `core::hash::BuildHasher` trait so it can  | 
41 |  | -//! construct both 32-bit and 64-bit hashers. To constrain the type to only produce 32-bit hasher  | 
42 |  | -//! you can add the trait bound `H::Hasher: hash32::Hasher`  | 
43 |  | -//!  | 
44 | 37 | //! # MSRV  | 
45 | 38 | //!  | 
46 | 39 | //! This crate is guaranteed to compile on latest stable Rust. It *might* compile on older  | 
 | 
55 | 48 | )]  | 
56 | 49 | #![no_std]  | 
57 | 50 | 
 
  | 
58 |  | -use core::fmt;  | 
59 |  | -use core::hash::BuildHasher;  | 
60 |  | -use core::marker::PhantomData;  | 
61 |  | - | 
62 | 51 | pub use crate::fnv::Hasher as FnvHasher;  | 
63 | 52 | pub use crate::murmur3::Hasher as Murmur3Hasher;  | 
64 | 53 | 
 
  | 
65 | 54 | mod fnv;  | 
66 | 55 | mod murmur3;  | 
67 | 56 | 
 
  | 
68 |  | -/// A copy of [`core::hash::BuildHasherDefault`][0], but with a const constructor.  | 
69 |  | -///  | 
70 |  | -/// This will eventually be deprecated once the version in `core` becomes const-constructible  | 
71 |  | -/// (presumably using `const Default`).  | 
72 |  | -///  | 
73 |  | -/// [0]: https://doc.rust-lang.org/core/hash/struct.BuildHasherDefault.html  | 
74 |  | -pub struct BuildHasherDefault<H> {  | 
75 |  | -    _marker: PhantomData<H>,  | 
76 |  | -}  | 
77 |  | - | 
78 |  | -impl<H> Default for BuildHasherDefault<H> {  | 
79 |  | -    fn default() -> Self {  | 
80 |  | -        Self {  | 
81 |  | -            _marker: PhantomData,  | 
82 |  | -        }  | 
83 |  | -    }  | 
84 |  | -}  | 
85 |  | - | 
86 |  | -impl<H> Clone for BuildHasherDefault<H> {  | 
87 |  | -    fn clone(&self) -> Self {  | 
88 |  | -        Self::default()  | 
89 |  | -    }  | 
90 |  | -}  | 
91 |  | - | 
92 |  | -impl<H> PartialEq for BuildHasherDefault<H> {  | 
93 |  | -    fn eq(&self, _other: &Self) -> bool {  | 
94 |  | -        true  | 
95 |  | -    }  | 
96 |  | -}  | 
97 |  | - | 
98 |  | -impl<H> Eq for BuildHasherDefault<H> {}  | 
99 |  | - | 
100 |  | -impl<H> fmt::Debug for BuildHasherDefault<H> {  | 
101 |  | -    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {  | 
102 |  | -        f.pad("BuildHasherDefault")  | 
103 |  | -    }  | 
104 |  | -}  | 
105 |  | - | 
106 |  | -impl<H> BuildHasherDefault<H> {  | 
107 |  | -    /// `const` constructor  | 
108 |  | -    pub const fn new() -> Self {  | 
109 |  | -        Self {  | 
110 |  | -            _marker: PhantomData,  | 
111 |  | -        }  | 
112 |  | -    }  | 
113 |  | -}  | 
114 |  | - | 
115 |  | -impl<H> BuildHasher for BuildHasherDefault<H>  | 
116 |  | -where  | 
117 |  | -    H: Default + core::hash::Hasher,  | 
118 |  | -{  | 
119 |  | -    type Hasher = H;  | 
120 |  | - | 
121 |  | -    fn build_hasher(&self) -> Self::Hasher {  | 
122 |  | -        H::default()  | 
123 |  | -    }  | 
124 |  | -}  | 
125 |  | - | 
126 | 57 | /// An extension of [core::hash::Hasher][0] for hashers which use 32 bits.  | 
127 | 58 | ///  | 
128 | 59 | /// For hashers which implement this trait, the standard `finish` method should just return a  | 
 | 
0 commit comments