1use slotmap::new_key_type;
9use std::fmt;
10
11pub type DocumentId = u32;
13
14#[derive(Clone, Copy, PartialEq, Eq, Hash)]
22pub struct NameId(pub u32);
23
24impl fmt::Debug for NameId {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "NameId({})", self.0)
27 }
28}
29
30impl fmt::Display for NameId {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "${}", self.0)
33 }
34}
35
36new_key_type! {
40 pub struct SimpleTypeKey;
42
43 pub struct ComplexTypeKey;
45
46 pub struct ElementKey;
48
49 pub struct AttributeKey;
51
52 pub struct AttributeGroupKey;
54
55 pub struct ModelGroupKey;
57
58 pub struct NotationKey;
60
61 pub struct IdentityConstraintKey;
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
67pub enum TypeKey {
68 Simple(SimpleTypeKey),
69 Complex(ComplexTypeKey),
70}
71
72impl TypeKey {
73 pub fn as_simple(&self) -> Option<SimpleTypeKey> {
74 match self {
75 TypeKey::Simple(key) => Some(*key),
76 _ => None,
77 }
78 }
79
80 pub fn as_complex(&self) -> Option<ComplexTypeKey> {
81 match self {
82 TypeKey::Complex(key) => Some(*key),
83 _ => None,
84 }
85 }
86}
87
88impl From<SimpleTypeKey> for TypeKey {
89 fn from(key: SimpleTypeKey) -> Self {
90 TypeKey::Simple(key)
91 }
92}
93
94impl From<ComplexTypeKey> for TypeKey {
95 fn from(key: ComplexTypeKey) -> Self {
96 TypeKey::Complex(key)
97 }
98}