xsd_parser/types/info/
reference.rs1use std::hash::{Hash, Hasher};
4
5use crate::schema::{MaxOccurs, MinOccurs};
6use crate::types::{Ident, TypeEq, Types};
7
8#[derive(Debug, Clone)]
10pub struct ReferenceInfo {
11 pub type_: Ident,
13
14 pub min_occurs: MinOccurs,
16
17 pub max_occurs: MaxOccurs,
19}
20
21impl ReferenceInfo {
22 #[must_use]
24 pub fn new<T>(type_: T) -> Self
25 where
26 T: Into<Ident>,
27 {
28 Self {
29 type_: type_.into(),
30 min_occurs: 1,
31 max_occurs: MaxOccurs::Bounded(1),
32 }
33 }
34
35 #[must_use]
40 pub fn is_single(&self) -> bool {
41 self.min_occurs == 1 && self.max_occurs == MaxOccurs::Bounded(1)
42 }
43
44 #[must_use]
46 pub fn min_occurs(mut self, min: MinOccurs) -> Self {
47 self.min_occurs = min;
48
49 self
50 }
51
52 #[must_use]
54 pub fn max_occurs(mut self, max: MaxOccurs) -> Self {
55 self.max_occurs = max;
56
57 self
58 }
59}
60
61impl TypeEq for ReferenceInfo {
62 fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &Types) {
63 let Self {
64 type_,
65 min_occurs,
66 max_occurs,
67 } = self;
68
69 type_.type_hash(hasher, types);
70 min_occurs.hash(hasher);
71 max_occurs.hash(hasher);
72 }
73
74 fn type_eq(&self, other: &Self, types: &Types) -> bool {
75 let Self {
76 type_,
77 min_occurs,
78 max_occurs,
79 } = self;
80
81 type_.type_eq(&other.type_, types)
82 && min_occurs.eq(&other.min_occurs)
83 && max_occurs.eq(&other.max_occurs)
84 }
85}