xsd_parser/types/info/
attribute.rs1use std::hash::{Hash, Hasher};
4use std::ops::{Deref, DerefMut};
5
6use crate::schema::xs::Use;
7use crate::types::{Ident, TypeEq, Types};
8
9use super::use_hash;
10
11#[derive(Debug, Clone)]
13pub struct AttributeInfo {
14 pub ident: Ident,
16
17 pub type_: Ident,
19
20 pub use_: Use,
22
23 pub default: Option<String>,
25
26 pub display_name: Option<String>,
28}
29
30#[derive(Default, Debug, Clone)]
32pub struct AttributesInfo(Vec<AttributeInfo>);
33
34impl AttributeInfo {
37 #[must_use]
39 pub fn new(ident: Ident, type_: Ident) -> Self {
40 Self {
41 ident,
42 type_,
43 use_: Use::Optional,
44 default: None,
45 display_name: None,
46 }
47 }
48
49 #[must_use]
51 pub fn with_use(mut self, use_: Use) -> Self {
52 self.use_ = use_;
53
54 self
55 }
56}
57
58impl TypeEq for AttributeInfo {
59 fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &Types) {
60 let Self {
61 ident,
62 type_,
63 use_,
64 default,
65 display_name,
66 } = self;
67
68 ident.hash(hasher);
69 type_.type_hash(hasher, types);
70 use_hash(use_, hasher);
71 default.hash(hasher);
72 display_name.hash(hasher);
73 }
74
75 fn type_eq(&self, other: &Self, types: &Types) -> bool {
76 let Self {
77 ident,
78 type_,
79 use_,
80 default,
81 display_name,
82 } = self;
83
84 ident.eq(&other.ident)
85 && type_.type_eq(&other.type_, types)
86 && use_.eq(&other.use_)
87 && default.eq(&other.default)
88 && display_name.eq(&other.display_name)
89 }
90}
91
92impl Deref for AttributesInfo {
95 type Target = Vec<AttributeInfo>;
96
97 fn deref(&self) -> &Self::Target {
98 &self.0
99 }
100}
101
102impl DerefMut for AttributesInfo {
103 fn deref_mut(&mut self) -> &mut Self::Target {
104 &mut self.0
105 }
106}
107
108impl TypeEq for AttributesInfo {
109 fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &Types) {
110 TypeEq::type_hash_slice(&self.0, hasher, types);
111 }
112
113 fn type_eq(&self, other: &Self, types: &Types) -> bool {
114 TypeEq::type_eq_iter(self.0.iter(), other.0.iter(), types)
115 }
116}