syntax_parser_generator/handles/collections/handle_bit_set/
eq.rs

1use std::hash::{Hash, Hasher};
2
3use crate::handles::collections::handle_bit_set::HandleBitSet;
4use crate::handles::Handled;
5
6impl<T> HandleBitSet<T>
7where
8    T: Handled,
9{
10    fn canonicalize(&self) -> Self {
11        // Removes trailing zeros to get the set into its canonical form
12        let mut bytes = self.bytes.clone();
13        while let Some(&0) = bytes.last() {
14            bytes.pop();
15        }
16        Self {
17            bytes,
18            phantom_data: Default::default(),
19        }
20    }
21}
22
23impl<T> PartialEq for HandleBitSet<T>
24where
25    T: Handled,
26{
27    fn eq(&self, other: &Self) -> bool {
28        self.canonicalize().bytes == other.canonicalize().bytes
29    }
30}
31
32impl<T: Handled> Eq for HandleBitSet<T> {}
33
34impl<T: Handled> Hash for HandleBitSet<T> {
35    fn hash<H: Hasher>(&self, state: &mut H) {
36        self.canonicalize().bytes.hash(state)
37    }
38}