1use core::iter::Sum;
2use core::ops;
3
4#[allow(unused)]
5pub trait ToSpecificity: Sized {
6 fn specificity(&self) -> Specificity;
7}
8
9#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
10pub struct Specificity(pub u8, pub u8, pub u8);
11
12impl ops::AddAssign for Specificity {
13 fn add_assign(&mut self, other: Self) {
14 self.0 = self.0.saturating_add(other.0);
15 self.1 = self.1.saturating_add(other.1);
16 self.2 = self.2.saturating_add(other.2);
17 }
18}
19
20impl ops::Add for Specificity {
21 type Output = Self;
22 fn add(self, other: Self) -> Self {
23 Self(self.0.saturating_add(other.0), self.1.saturating_add(other.1), self.2.saturating_add(other.2))
24 }
25}
26
27impl Sum for Specificity {
28 fn sum<I: Iterator<Item = Specificity>>(iter: I) -> Specificity {
29 let mut out = Specificity(0, 0, 0);
30 for specificity in iter {
31 out += specificity
32 }
33 out
34 }
35}