xsd_parser/types/info/
element.rs1use std::hash::{Hash, Hasher};
4use std::ops::{Deref, DerefMut};
5
6use crate::schema::{MaxOccurs, MinOccurs};
7use crate::types::{Ident, TypeEq, Types};
8
9#[derive(Debug, Clone)]
11pub struct ElementInfo {
12 pub ident: Ident,
14
15 pub type_: Ident,
17
18 pub min_occurs: MinOccurs,
20
21 pub max_occurs: MaxOccurs,
23
24 pub element_mode: ElementMode,
26
27 pub display_name: Option<String>,
29}
30
31#[derive(Default, Debug, Clone)]
33pub struct ElementsInfo(pub Vec<ElementInfo>);
34
35#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
37pub enum ElementMode {
38 Element,
40
41 Group,
43}
44
45impl ElementInfo {
48 #[must_use]
51 pub fn new(ident: Ident, type_: Ident, element_mode: ElementMode) -> Self {
52 Self {
53 ident,
54 type_,
55 element_mode,
56 min_occurs: 1,
57 max_occurs: MaxOccurs::Bounded(1),
58 display_name: None,
59 }
60 }
61}
62
63impl TypeEq for ElementInfo {
64 fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &Types) {
65 let Self {
66 ident,
67 type_,
68 element_mode,
69 min_occurs,
70 max_occurs,
71 display_name,
72 } = self;
73
74 ident.hash(hasher);
75 type_.type_hash(hasher, types);
76 element_mode.hash(hasher);
77 min_occurs.hash(hasher);
78 max_occurs.hash(hasher);
79 display_name.hash(hasher);
80 }
81
82 fn type_eq(&self, other: &Self, types: &Types) -> bool {
83 let Self {
84 ident,
85 type_,
86 element_mode,
87 min_occurs,
88 max_occurs,
89 display_name,
90 } = self;
91
92 ident.eq(&other.ident)
93 && type_.type_eq(&other.type_, types)
94 && element_mode.eq(&other.element_mode)
95 && min_occurs.eq(&other.min_occurs)
96 && max_occurs.eq(&other.max_occurs)
97 && display_name.eq(&other.display_name)
98 }
99}
100
101impl Deref for ElementsInfo {
104 type Target = Vec<ElementInfo>;
105
106 fn deref(&self) -> &Self::Target {
107 &self.0
108 }
109}
110
111impl DerefMut for ElementsInfo {
112 fn deref_mut(&mut self) -> &mut Self::Target {
113 &mut self.0
114 }
115}
116
117impl TypeEq for ElementsInfo {
118 fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &Types) {
119 TypeEq::type_hash_slice(&self.0, hasher, types);
120 }
121
122 fn type_eq(&self, other: &Self, types: &Types) -> bool {
123 TypeEq::type_eq_iter(self.0.iter(), other.0.iter(), types)
124 }
125}