xsd_parser/models/meta/
dynamic.rs1use std::hash::{Hash, Hasher};
4
5use crate::models::TypeIdent;
6
7use super::{MetaTypes, TypeEq};
8
9#[derive(Default, Debug, Clone)]
11pub struct DynamicMeta {
12 pub type_: Option<TypeIdent>,
14
15 pub derived_types: Vec<DerivedTypeMeta>,
17}
18
19#[derive(Debug, Clone)]
21pub struct DerivedTypeMeta {
22 pub type_: TypeIdent,
24
25 pub display_name: Option<String>,
27}
28
29impl TypeEq for DynamicMeta {
30 fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) {
31 let Self {
32 type_,
33 derived_types,
34 } = self;
35
36 type_.type_hash(hasher, types);
37 TypeEq::type_hash_slice(derived_types, hasher, types);
38 }
39
40 fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool {
41 let Self {
42 type_,
43 derived_types,
44 } = self;
45
46 type_.type_eq(&other.type_, types)
47 && TypeEq::type_eq_iter(derived_types.iter(), other.derived_types.iter(), types)
48 }
49}
50
51impl DerivedTypeMeta {
52 #[must_use]
54 pub fn new(type_: TypeIdent) -> Self {
55 Self {
56 type_,
57 display_name: None,
58 }
59 }
60}
61
62impl TypeEq for DerivedTypeMeta {
63 fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) {
64 let Self {
65 type_,
66 display_name,
67 } = self;
68
69 type_.type_hash(hasher, types);
70 display_name.hash(hasher);
71 }
72
73 fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool {
74 let Self {
75 type_,
76 display_name,
77 } = self;
78
79 type_.type_eq(&other.type_, types) && display_name == &other.display_name
80 }
81}