xiss_map/
id.rs

1use std::fmt;
2
3use smol_str::SmolStr;
4
5#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
6pub enum IdKind {
7    Class,
8    Var,
9    Keyframes,
10}
11
12impl fmt::Display for IdKind {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            IdKind::Class => f.write_str("class"),
16            IdKind::Var => f.write_str("var"),
17            IdKind::Keyframes => f.write_str("keyframes"),
18        }
19    }
20}
21
22#[derive(Debug, Clone, PartialEq)]
23pub struct Id {
24    pub kind: IdKind,
25    pub module_id: SmolStr,
26    pub local_id: SmolStr,
27    pub global_id: SmolStr,
28}
29
30impl Id {
31    pub fn new(kind: IdKind, module_id: SmolStr, local_id: SmolStr, global_id: SmolStr) -> Self {
32        Self {
33            kind,
34            module_id,
35            local_id,
36            global_id,
37        }
38    }
39}
40
41impl<'a> fmt::Display for Id {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        write!(
44            f,
45            "{},{},{},{}\n",
46            self.module_id, self.kind, self.local_id, self.global_id,
47        )
48    }
49}