tinymist_world/parser/
modifier_set.rs

1use std::ops;
2
3use super::typst_tokens::Modifier;
4
5#[derive(Default, Clone, Copy)]
6pub struct ModifierSet(u32);
7
8impl ModifierSet {
9    pub fn empty() -> Self {
10        Self::default()
11    }
12
13    pub fn new(modifiers: &[Modifier]) -> Self {
14        let bits = modifiers
15            .iter()
16            .copied()
17            .map(Modifier::bitmask)
18            .fold(0, |bits, mask| bits | mask);
19        Self(bits)
20    }
21
22    pub fn bitset(self) -> u32 {
23        self.0
24    }
25}
26
27impl ops::BitOr for ModifierSet {
28    type Output = Self;
29
30    fn bitor(self, rhs: Self) -> Self::Output {
31        Self(self.0 | rhs.0)
32    }
33}