Skip to main content

turbo_trace_server/
string_tuple_ref.rs

1use hashbrown::Equivalent;
2use turbo_rcstr::RcStr;
3
4#[derive(Hash)]
5pub struct StringTupleRef<'a>(pub &'a str, pub &'a str);
6
7impl<'a> Equivalent<(RcStr, RcStr)> for StringTupleRef<'a> {
8    fn equivalent(&self, other: &(RcStr, RcStr)) -> bool {
9        other.0 == self.0 && other.1 == self.1
10    }
11}
12
13#[cfg(test)]
14mod string_tuple_ref_tests {
15    use std::hash::BuildHasher;
16
17    use rustc_hash::FxBuildHasher;
18
19    use super::*;
20
21    #[test]
22    fn test_string_tuple_ref_hash() {
23        let s = FxBuildHasher;
24        assert_eq!(
25            s.hash_one(StringTupleRef("abc", "def")),
26            s.hash_one(&(RcStr::from("abc"), RcStr::from("def")))
27        );
28
29        assert_eq!(
30            s.hash_one(StringTupleRef(
31                "a_very_long_string_that_is_not_inlined",
32                "def"
33            )),
34            s.hash_one(&(
35                RcStr::from("a_very_long_string_that_is_not_inlined"),
36                RcStr::from("def")
37            ))
38        );
39    }
40}