glossa_shared/
phf_triple_key.rs

1use core::hash::{Hash, Hasher};
2
3use phf_shared::{FmtConst, PhfBorrow, PhfHash};
4
5use crate::MiniStr;
6
7#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Copy)]
8pub struct PhfTripleKey<'a>(pub &'a str, pub &'a str, pub &'a str);
9
10impl PhfHash for PhfTripleKey<'_> {
11  fn phf_hash<H: Hasher>(&self, state: &mut H) {
12    self.0.hash(state);
13    self.1.hash(state);
14    self.2.hash(state);
15  }
16}
17
18impl PhfBorrow<Self> for PhfTripleKey<'_> {
19  fn borrow(&self) -> &Self {
20    self
21  }
22}
23
24impl FmtConst for PhfTripleKey<'_> {
25  fn fmt_const(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
26    let Self(lang, map, key) = self;
27    write!(
28      f,
29      r#####"Key(r#"{lang}"#, r##"{map}"##, r###"{key}"###)"#####
30    )
31  }
32}
33// --------
34
35#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
36pub struct RawTripleKey<'a>(pub MiniStr, pub &'a str, pub &'a str);
37impl PhfHash for RawTripleKey<'_> {
38  fn phf_hash<H: Hasher>(&self, state: &mut H) {
39    self.0.as_str().hash(state);
40    self.1.hash(state);
41    self.2.hash(state);
42  }
43}
44impl PhfBorrow<Self> for RawTripleKey<'_> {
45  fn borrow(&self) -> &Self {
46    self
47  }
48}
49impl FmtConst for RawTripleKey<'_> {
50  fn fmt_const(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
51    let Self(lang, map, key) = self;
52    write!(
53      f,
54      r#####"Key(r#"{lang}"#, r##"{map}"##, r###"{key}"###)"#####
55    )
56  }
57}