|
1 | | -//! Contains the [`DynamicMeta`] type information and all related types. |
| 1 | +//! Contains the [`SubstitutionMeta`] type information and all related types. |
2 | 2 |
|
3 | 3 | use std::hash::{Hash, Hasher}; |
4 | 4 |
|
| 5 | +use indexmap::IndexMap; |
| 6 | + |
5 | 7 | use crate::models::TypeIdent; |
6 | 8 |
|
7 | 9 | use super::{MetaTypes, TypeEq}; |
8 | 10 |
|
9 | | -/// Type information that contains data about dynamic types. |
| 11 | +/// Type information that contains data about dynamic elements (substitution groups) or types. |
10 | 12 | #[derive(Default, Debug, Clone)] |
11 | 13 | pub struct DynamicMeta { |
12 | | - /// Base type of the dynamic type. |
| 14 | + /// Base type of this dynamic type. |
13 | 15 | pub type_: Option<TypeIdent>, |
14 | 16 |
|
15 | | - /// List of derived types. |
16 | | - pub derived_types: Vec<DerivedTypeMeta>, |
17 | | -} |
| 17 | + /// Whether the type was defined as abstract or not. |
| 18 | + pub is_abstract: bool, |
18 | 19 |
|
19 | | -/// Meta^ information about a derived type. |
20 | | -#[derive(Debug, Clone)] |
21 | | -pub struct DerivedTypeMeta { |
22 | | - /// Identifier of the derived type. |
23 | | - pub type_: TypeIdent, |
24 | | - |
25 | | - /// Name of the element to use inside the generated code. |
26 | | - pub display_name: Option<String>, |
| 20 | + /// Map of the derived types of this dynamic type. |
| 21 | + pub derived_types: IndexMap<TypeIdent, DerivedTypeMeta>, |
27 | 22 | } |
28 | 23 |
|
29 | 24 | impl TypeEq for DynamicMeta { |
30 | 25 | fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) { |
31 | 26 | let Self { |
32 | 27 | type_, |
| 28 | + is_abstract, |
33 | 29 | derived_types, |
34 | 30 | } = self; |
35 | 31 |
|
36 | 32 | type_.type_hash(hasher, types); |
37 | | - TypeEq::type_hash_slice(derived_types, hasher, types); |
| 33 | + is_abstract.hash(hasher); |
| 34 | + TypeEq::type_hash_iter(derived_types, hasher, types); |
38 | 35 | } |
39 | 36 |
|
40 | 37 | fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool { |
41 | 38 | let Self { |
42 | 39 | type_, |
| 40 | + is_abstract, |
43 | 41 | derived_types, |
44 | 42 | } = self; |
45 | 43 |
|
46 | 44 | type_.type_eq(&other.type_, types) |
| 45 | + && is_abstract == &other.is_abstract |
47 | 46 | && TypeEq::type_eq_iter(derived_types.iter(), other.derived_types.iter(), types) |
48 | 47 | } |
49 | 48 | } |
50 | 49 |
|
51 | | -impl DerivedTypeMeta { |
52 | | - /// Creates a new [`DerivedTypeMeta`] instance with the given `type_`. |
53 | | - #[must_use] |
54 | | - pub fn new(type_: TypeIdent) -> Self { |
55 | | - Self { |
56 | | - type_, |
57 | | - display_name: None, |
58 | | - } |
59 | | - } |
| 50 | +/// Meta information about a single derived type of a dynamic type. |
| 51 | +#[derive(Default, Debug, Clone)] |
| 52 | +pub struct DerivedTypeMeta { |
| 53 | + /// Is set to `true` if this derived type is directly defined in the dynamic type, |
| 54 | + /// otherwise it is inherited from another dynamic type. |
| 55 | + pub is_direct: bool, |
| 56 | + |
| 57 | + /// Name of the element to use inside the generated code. |
| 58 | + pub display_name: Option<String>, |
60 | 59 | } |
61 | 60 |
|
62 | 61 | impl TypeEq for DerivedTypeMeta { |
63 | | - fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) { |
| 62 | + fn type_hash<H: Hasher>(&self, hasher: &mut H, _types: &MetaTypes) { |
64 | 63 | let Self { |
65 | | - type_, |
66 | 64 | display_name, |
| 65 | + is_direct, |
67 | 66 | } = self; |
68 | 67 |
|
69 | | - type_.type_hash(hasher, types); |
70 | 68 | display_name.hash(hasher); |
| 69 | + is_direct.hash(hasher); |
71 | 70 | } |
72 | 71 |
|
73 | | - fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool { |
| 72 | + fn type_eq(&self, other: &Self, _types: &MetaTypes) -> bool { |
74 | 73 | let Self { |
75 | | - type_, |
76 | 74 | display_name, |
| 75 | + is_direct, |
77 | 76 | } = self; |
78 | 77 |
|
79 | | - type_.type_eq(&other.type_, types) && display_name == &other.display_name |
| 78 | + display_name == &other.display_name && is_direct == &other.is_direct |
80 | 79 | } |
81 | 80 | } |
0 commit comments