Debian Codegraph @

debian/missing-sources/phf_shared/src/lib.rs

raw symbols SCIP
1 //! See [the `phf` crate's documentation][phf] for details.
2 //!
3 //! [phf]: https://docs.rs/phf
4
5 #![doc(html_root_url = "https://docs.rs/phf_shared/0.13.1")]
6 #![cfg_attr(not(feature = "std"), no_std)]
7
8 #[cfg(feature = "std")]
9 extern crate std as corerust-analyzer cargo phf_shared 0.13.1 core/;
10
11 use corerust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
12 use corerust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#};
13 use corerust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::Wrappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/Wrapping#;
14 use siphasherrust-analyzer cargo siphasher 1.0.2 crate/::sip128rust-analyzer cargo siphasher 1.0.2 sip128/::{Hash128rust-analyzer cargo siphasher 1.0.2 sip128/Hash128#, Hasher128rust-analyzer cargo siphasher 1.0.2 sip128/Hasher128#, SipHasher13rust-analyzer cargo siphasher 1.0.2 sip128/SipHasher13#};
15
16 #[non_exhaustive]
17 pub struct Hashesrust-analyzer cargo phf_shared 0.13.1 Hashes# {
18 pub grust-analyzer cargo phf_shared 0.13.1 Hashes#g.: u32,
19 pub f1rust-analyzer cargo phf_shared 0.13.1 Hashes#f1.: u32,
20 pub f2rust-analyzer cargo phf_shared 0.13.1 Hashes#f2.: u32,
21 }
22
23 /// A central typedef for hash keys
24 ///
25 /// Makes experimentation easier by only needing to be updated here.
26 pub type HashKeyrust-analyzer cargo phf_shared 0.13.1 HashKey# = u64;
27
28 #[inline]
29 pub fn displacerust-analyzer cargo phf_shared 0.13.1 displace().(f1: u32, f2: u32, d1: u32, d2: u32) -> u32 {
30 (Wrappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/Wrapping#(d2) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Add<Self>`]add().Wrappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/Wrapping#(f1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Mul<Self>`]mul().Wrappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/Wrapping#(d1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/impl#[`Wrapping<u32>`][`Add<Self>`]add().Wrappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/Wrapping#(f2)).0rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/wrapping/Wrapping#0.
31 }
32
33 /// `key` is from `phf_generator::HashState`.
34 #[inline]
35 pub fn hashrust-analyzer cargo phf_shared 0.13.1 hash().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash#>(x: &T, key: &HashKeyrust-analyzer cargo phf_shared 0.13.1 HashKey#) -> Hashesrust-analyzer cargo phf_shared 0.13.1 Hashes# {
36 let mut hasher = SipHasher13rust-analyzer cargo siphasher 1.0.2 sip128/SipHasher13#::new_with_keysrust-analyzer cargo siphasher 1.0.2 sip128/impl#[SipHasher13]new_with_keys().(0, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().key);
37 x.phf_hashrust-analyzer cargo phf_shared 0.13.1 PhfHash#phf_hash().(&mut hasher);
38
39 let Hash128rust-analyzer cargo siphasher 1.0.2 sip128/Hash128# {
40 h1rust-analyzer cargo siphasher 1.0.2 sip128/Hash128#h1.: lower,
41 h2rust-analyzer cargo siphasher 1.0.2 sip128/Hash128#h2.: upper,
42 } = hasher.finish128rust-analyzer cargo siphasher 1.0.2 sip128/impl#[SipHasher13][Hasher128]finish128().();
43
44 Hashesrust-analyzer cargo phf_shared 0.13.1 Hashes# {
45 grust-analyzer cargo phf_shared 0.13.1 Hashes#g.: (lower rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().32) as u32,
46 f1rust-analyzer cargo phf_shared 0.13.1 Hashes#f1.: lower as u32,
47 f2rust-analyzer cargo phf_shared 0.13.1 Hashes#f2.: upper as u32,
48 }
49 }
50
51 /// Return an index into `phf_generator::HashState::map`.
52 ///
53 /// * `hash` is from `hash()` in this crate.
54 /// * `disps` is from `phf_generator::HashState::disps`.
55 /// * `len` is the length of `phf_generator::HashState::map`.
56 #[inline]
57 pub fn get_indexrust-analyzer cargo phf_shared 0.13.1 get_index().(hashes: &Hashesrust-analyzer cargo phf_shared 0.13.1 Hashes#, disps: &[(u32, u32)], len: usize) -> u32 {
58 let (d1, d2) = disps[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().(hashes.grust-analyzer cargo phf_shared 0.13.1 Hashes#g. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().(disps.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u32)) as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
59 displacerust-analyzer cargo phf_shared 0.13.1 displace().(hashes.f1rust-analyzer cargo phf_shared 0.13.1 Hashes#f1., hashes.f2rust-analyzer cargo phf_shared 0.13.1 Hashes#f2., d1, d2) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().(len as u32)
60 }
61
62 /// A trait implemented by types which can be used in PHF data structures.
63 ///
64 /// This differs from the standard library's `Hash` trait in that `PhfHash`'s
65 /// results must be architecture independent so that hashes will be consistent
66 /// between the host and target when cross compiling.
67 pub trait PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# {
68 /// Feeds the value into the state given, updating the hasher as necessary.
69 fn phf_hashrust-analyzer cargo phf_shared 0.13.1 PhfHash#phf_hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H);
70
71 /// Feeds a slice of this type into the state provided.
72 fn phf_hash_slicerust-analyzer cargo phf_shared 0.13.1 PhfHash#phf_hash_slice().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(data: &[Self], state: &mut H)
73 where
74 Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
75 {
76 for piece in data {
77 piece.phf_hashrust-analyzer cargo phf_shared 0.13.1 PhfHash#phf_hash().(state);
78 }
79 }
80 }
81
82 /// Trait for printing types with `const` constructors, used by `phf_codegen` and `phf_macros`.
83 pub trait FmtConstrust-analyzer cargo phf_shared 0.13.1 FmtConst# {
84 /// Print a `const` expression representing this value.
85 fn fmt_construst-analyzer cargo phf_shared 0.13.1 FmtConst#fmt_const().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#;
86 }
87
88 /// Identical to `std::borrow::Borrow` except omitting blanket impls to facilitate other
89 /// borrowing patterns.
90 ///
91 /// The same semantic requirements apply:
92 ///
93 /// > In particular `Eq`, `Ord` and `Hash` must be equivalent for borrowed and owned values:
94 /// > `x.borrow() == y.borrow()` should give the same result as `x == y`.
95 ///
96 /// (This crate's API only requires `Eq` and `PhfHash`, however.)
97 ///
98 /// ### Motivation
99 /// The conventional signature for lookup methods on collections looks something like this:
100 ///
101 /// ```ignore
102 /// impl<K, V> Map<K, V> where K: PhfHash + Eq {
103 /// fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: PhfHash + Eq, K: Borrow<T> {
104 /// ...
105 /// }
106 /// }
107 /// ```
108 ///
109 /// This allows the key type used for lookup to be different than the key stored in the map so for
110 /// example you can use `&str` to look up a value in a `Map<String, _>`. However, this runs into
111 /// a problem in the case where `T` and `K` are both a `Foo<_>` type constructor but
112 /// the contained type is different (even being the same type with different lifetimes).
113 ///
114 /// The main issue for this crate's API is that, with this method signature, you cannot perform a
115 /// lookup on a `Map<UniCase<&'static str>, _>` with a `UniCase<&'a str>` where `'a` is not
116 /// `'static`; there is no impl of `Borrow` that resolves to
117 /// `impl Borrow<UniCase<'a>> for UniCase<&'static str>` and one cannot be added either because of
118 /// all the blanket impls.
119 ///
120 /// Instead, this trait is implemented conservatively, without blanket impls, so that impls like
121 /// this may be added. This is feasible since the set of types that implement `PhfHash` is
122 /// intentionally small.
123 ///
124 /// This likely won't be fixable with specialization alone but will require full support for lattice
125 /// impls since we technically want to add overlapping blanket impls.
126 pub trait PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<B: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> {
127 /// Convert a reference to `self` to a reference to the borrowed type.
128 fn borrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#borrow().(&self) -> &B;
129 }
130
131 /// Create an impl of `FmtConst` delegating to `fmt::Debug` for types that can deal with it.
132 ///
133 /// Ideally with specialization this could be just one default impl and then specialized where
134 /// it doesn't apply.
135 macro_rules! delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug! (
136 ($ty:ty) => {
137 impl FmtConst for $ty {
138 fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139 write!(f, "{:?}", self)
140 }
141 }
142 }
143 );
144
145 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(str);
146 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(char);
147 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(u8);
148 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(i8);
149 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(u16);
150 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(i16);
151 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(u32);
152 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(i32);
153 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(u64);
154 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(i64);
155 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(usize);
156 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(isize);
157 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(u128);
158 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(i128);
159 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(bool);
160
161 /// `impl PhfBorrow<T> for T`
162 macro_rules! impl_reflexiverust-analyzer cargo phf_shared 0.13.1 impl_reflexive!(
163 ($($t:ty),*) => (
164 $(impl PhfBorrow<$t> for $t {
165 fn borrow(&self) -> &$t {
166 self
167 }
168 })*
169 )
170 );
171
172 impl_reflexiverust-analyzer cargo phf_shared 0.13.1 impl_reflexive!!(
173 str,
174 char,
175 u8,
176 i8,
177 u16,
178 i16,
179 u32,
180 i32,
181 u64,
182 i64,
183 usize,
184 isize,
185 u128,
186 i128,
187 bool,
188 [u8]
189 );
190
191 #[cfg(feature = "std")]
192 impl PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<str> for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
193 fn borrowrust-analyzer cargo phf_shared 0.13.1 impl#[String][`PhfBorrow<str>`]borrow().(&self) -> &str {
194 self
195 }
196 }
197
198 #[cfg(feature = "std")]
199 impl PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<[u8]> for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
200 fn borrowrust-analyzer cargo phf_shared 0.13.1 impl#[`Vec<u8>`][`PhfBorrow<[u8]>`]borrow().(&self) -> &[u8] {
201 self
202 }
203 }
204
205 #[cfg(feature = "std")]
206 delegate_debugrust-analyzer cargo phf_shared 0.13.1 delegate_debug!!(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#);
207
208 #[cfg(feature = "std")]
209 impl PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
210 #[inline]
211 fn phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[String][PhfHash]phf_hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
212 (*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[str][PhfHash]phf_hash().(state)
213 }
214 }
215
216 #[cfg(feature = "std")]
217 impl PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
218 #[inline]
219 fn phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[`Vec<u8>`][PhfHash]phf_hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
220 (*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[`[u8]`][PhfHash]phf_hash().(state)
221 }
222 }
223
224 impl<'a, T: 'a + PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for &'a T {
225 fn phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[`&'a T`][PhfHash]phf_hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
226 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).phf_hashrust-analyzer cargo phf_shared 0.13.1 PhfHash#phf_hash().(state)
227 }
228 }
229
230 impl<'a, T: 'a + FmtConstrust-analyzer cargo phf_shared 0.13.1 FmtConst# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> FmtConstrust-analyzer cargo phf_shared 0.13.1 FmtConst# for &'a T {
231 fn fmt_construst-analyzer cargo phf_shared 0.13.1 impl#[`&'a T`][FmtConst]fmt_const().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
232 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).fmt_construst-analyzer cargo phf_shared 0.13.1 FmtConst#fmt_const().(f)
233 }
234 }
235
236 impl PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<str> for &str {
237 fn borrowrust-analyzer cargo phf_shared 0.13.1 impl#[`&str`][`PhfBorrow<str>`]borrow().(&self) -> &str {
238 self
239 }
240 }
241
242 impl PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<[u8]> for &[u8] {
243 fn borrowrust-analyzer cargo phf_shared 0.13.1 impl#[`&[u8]`][`PhfBorrow<[u8]>`]borrow().(&self) -> &[u8] {
244 self
245 }
246 }
247
248 impl<const N: usize> PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<[u8; N]> for &[u8; N] {
249 fn borrowrust-analyzer cargo phf_shared 0.13.1 impl#[`&[u8; N]`][`PhfBorrow<[u8; N]>`]borrow().(&self) -> &[u8; N] {
250 self
251 }
252 }
253
254 impl PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for str {
255 #[inline]
256 fn phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[str][PhfHash]phf_hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
257 self.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[`[u8]`][PhfHash]phf_hash().(state)
258 }
259 }
260
261 impl PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for [u8] {
262 #[inline]
263 fn phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[`[u8]`][PhfHash]phf_hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
264 state.writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write().(self);
265 }
266 }
267
268 impl FmtConstrust-analyzer cargo phf_shared 0.13.1 FmtConst# for [u8] {
269 #[inline]
270 fn fmt_construst-analyzer cargo phf_shared 0.13.1 impl#[`[u8]`][FmtConst]fmt_const().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
271 // slices need a leading reference
272 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "&{:?}", self)
273 }
274 }
275
276 #[cfg(feature = "unicase")]
277 impl<S> PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for unicase::UniCase<S>
278 where
279 unicase::UniCase<S>: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
280 {
281 #[inline]
282 fn phf_hash<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
283 selfrust-analyzer cargo phf_shared 0.13.1 crate/.hash(state)
284 }
285 }
286
287 #[cfg(feature = "unicase")]
288 impl<S> FmtConstrust-analyzer cargo phf_shared 0.13.1 FmtConst# for unicase::UniCase<S>
289 where
290 S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>,
291 {
292 fn fmt_const(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
293 if selfrust-analyzer cargo phf_shared 0.13.1 crate/.is_ascii() {
294 f.write_str("UniCase::ascii(")?;
295 } else {
296 f.write_str("UniCase::unicode(")?;
297 }
298
299 selfrust-analyzer cargo phf_shared 0.13.1 crate/.as_ref().fmt_const(f)?;
300 f.write_str(")")
301 }
302 }
303
304 #[cfg(feature = "unicase")]
305 impl<'b, 'a: 'b, S: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + 'a> PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<unicase::UniCase<&'b S>> for unicase::UniCase<&'a S> {
306 fn borrow(&self) -> &unicase::UniCase<&'b S> {
307 selfrust-analyzer cargo phf_shared 0.13.1 crate/
308 }
309 }
310
311 #[cfg(feature = "unicase")]
312 impl<S> PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for unicase::Ascii<S>
313 where
314 unicase::Ascii<S>: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
315 {
316 #[inline]
317 fn phf_hash<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
318 selfrust-analyzer cargo phf_shared 0.13.1 crate/.hash(state)
319 }
320 }
321
322 #[cfg(feature = "unicase")]
323 impl<S> FmtConstrust-analyzer cargo phf_shared 0.13.1 FmtConst# for unicase::Ascii<S>
324 where
325 S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>,
326 {
327 fn fmt_const(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
328 f.write_str("Ascii::new(")?;
329 selfrust-analyzer cargo phf_shared 0.13.1 crate/.as_ref().fmt_const(f)?;
330 f.write_str(")")
331 }
332 }
333
334 #[cfg(feature = "unicase")]
335 impl<'b, 'a: 'b, S: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + 'a> PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<unicase::Ascii<&'b S>> for unicase::Ascii<&'a S> {
336 fn borrow(&self) -> &unicase::Ascii<&'b S> {
337 selfrust-analyzer cargo phf_shared 0.13.1 crate/
338 }
339 }
340
341 #[cfg(feature = "uncased")]
342 impl PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for uncased::UncasedStr {
343 #[inline]
344 fn phf_hash<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
345 selfrust-analyzer cargo phf_shared 0.13.1 crate/.hash(state)
346 }
347 }
348
349 #[cfg(feature = "uncased")]
350 impl FmtConstrust-analyzer cargo phf_shared 0.13.1 FmtConst# for uncased::UncasedStr {
351 fn fmt_const(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
352 f.write_str("UncasedStr::new(")?;
353 selfrust-analyzer cargo phf_shared 0.13.1 crate/.as_str().fmt_const(f)?;
354 f.write_str(")")
355 }
356 }
357
358 #[cfg(feature = "uncased")]
359 impl PhfBorrowrust-analyzer cargo phf_shared 0.13.1 PhfBorrow#<uncased::UncasedStr> for &uncased::UncasedStr {
360 fn borrow(&self) -> &uncased::UncasedStr {
361 selfrust-analyzer cargo phf_shared 0.13.1 crate/
362 }
363 }
364
365 macro_rules! sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl! (
366 (le $t:ty) => (
367 impl PhfHash for $t {
368 #[inline]
369 fn phf_hash<H: Hasher>(&self, state: &mut H) {
370 self.to_le().hash(state);
371 }
372 }
373 );
374 ($t:ty) => (
375 impl PhfHash for $t {
376 #[inline]
377 fn phf_hash<H: Hasher>(&self, state: &mut H) {
378 self.hash(state);
379 }
380 }
381 )
382 );
383
384 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(u8);
385 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(i8);
386 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le u16);
387 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le i16);
388 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le u32);
389 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le i32);
390 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le u64);
391 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le i64);
392 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le usize);
393 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le isize);
394 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le u128);
395 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(le i128);
396 sip_implrust-analyzer cargo phf_shared 0.13.1 sip_impl!!(bool);
397
398 impl PhfHashrust-analyzer cargo phf_shared 0.13.1 PhfHash# for char {
399 #[inline]
400 fn phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[char][PhfHash]phf_hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
401 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self as u32).phf_hashrust-analyzer cargo phf_shared 0.13.1 impl#[u32][PhfHash]phf_hash().(state)
402 }
403 }
404
405 // minimize duplicated code since formatting drags in quite a bit
406 fn fmt_arrayrust-analyzer cargo phf_shared 0.13.1 fmt_array().<T: corerust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#>(array: &[T], f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
407 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:?}", array)
408 }
409
410 macro_rules! array_implrust-analyzer cargo phf_shared 0.13.1 array_impl! (
411 ($t:ty) => (
412 impl<const N: usize> PhfHash for [$t; N] {
413 #[inline]
414 fn phf_hash<H: Hasher>(&self, state: &mut H) {
415 for v in &self[..] {
416 v.phf_hash(state);
417 }
418 }
419 }
420
421 impl<const N: usize> FmtConst for [$t; N] {
422 fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
423 fmt_array(self, f)
424 }
425 }
426
427 impl<const N: usize> PhfBorrow<[$t]> for [$t; N] {
428 fn borrow(&self) -> &[$t] {
429 self
430 }
431 }
432 )
433 );
434
435 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(u8);
436 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(i8);
437 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(u16);
438 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(i16);
439 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(u32);
440 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(i32);
441 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(u64);
442 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(i64);
443 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(usize);
444 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(isize);
445 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(u128);
446 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(i128);
447 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(bool);
448 array_implrust-analyzer cargo phf_shared 0.13.1 array_impl!!(char);
449
450 macro_rules! slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl! (
451 ($t:ty) => {
452 impl PhfHash for [$t] {
453 #[inline]
454 fn phf_hash<H: Hasher>(&self, state: &mut H) {
455 for v in self {
456 v.phf_hash(state);
457 }
458 }
459 }
460 };
461 );
462
463 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(i8);
464 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(u16);
465 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(i16);
466 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(u32);
467 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(i32);
468 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(u64);
469 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(i64);
470 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(usize);
471 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(isize);
472 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(u128);
473 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(i128);
474 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(bool);
475 slice_implrust-analyzer cargo phf_shared 0.13.1 slice_impl!!(char);
476
477 macro_rules! tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl! {
478 ($($t:ident),+) => {
479 impl<$($t: PhfHash),+> PhfHash for ($($t,)+) {
480 fn phf_hash<HS: Hasher>(&self, state: &mut HS) {
481 #[allow(non_snake_case)]
482 let ($($t,)+) = self;
483 $(
484 $t.phf_hash(state);
485 )+
486 }
487 }
488
489 impl<$($t: PhfHash),+> PhfBorrow<($($t,)+)> for ($($t,)+) {
490 fn borrow(&self) -> &($($t,)+) {
491 self
492 }
493 }
494
495 impl<$($t: FmtConst),+> FmtConst for ($($t,)+) {
496 fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
497 #[allow(non_snake_case)]
498 let ($($t,)+) = self;
499 write!(f, "(")?;
500 let mut first = true;
501 $(
502 if !core::mem::replace(&mut first, false) {
503 write!(f, ", ")?;
504 }
505 $t.fmt_const(f)?;
506 )+
507 write!(f, ")")
508 }
509 }
510 };
511 }
512
513 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A);
514 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B);
515 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C);
516 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D);
517 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E);
518 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E, F);
519 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E, F, G);
520 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E, F, G, HT);
521 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E, F, G, HT, I);
522 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E, F, G, HT, I, J);
523 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E, F, G, HT, I, J, K);
524 tuple_implrust-analyzer cargo phf_shared 0.13.1 tuple_impl!!(A, B, C, D, E, F, G, HT, I, J, K, L);