xsd_parser/pipeline/generator/meta.rs
1use std::ops::Deref;
2
3use crate::config::{BoxFlags, GeneratorFlags, TypedefMode};
4use crate::models::{code::IdentPath, meta::MetaTypes};
5
6/// Meta data of the generator process.
7///
8/// Contains different information and data that is useful during the code
9/// generation process.
10#[derive(Debug)]
11pub struct MetaData<'types> {
12 /// Reference to the types the code should be generated for.
13 pub types: &'types MetaTypes,
14
15 /// Flags that controls the behavior of the generator.
16 pub flags: GeneratorFlags,
17
18 /// List of postfixed to add to the name of the generated types.
19 ///
20 /// This corresponds to the variants of [`IdentType`](crate::models::IdentType).
21 pub postfixes: [String; 10],
22
23 /// Tells the generator how to deal with boxed elements.
24 pub box_flags: BoxFlags,
25
26 /// Tells the generator how to deal with type definitions.
27 pub typedef_mode: TypedefMode,
28
29 /// Type to use to store unformatted text.
30 pub text_type: IdentPath,
31
32 /// Type to use to store mixed types.
33 pub mixed_type: IdentPath,
34
35 /// Type to use to store nillable types.
36 pub nillable_type: IdentPath,
37
38 /// Type to use to store unstructured `xs:any` elements.
39 pub any_type: IdentPath,
40
41 /// Type to use to store unstructured `xs:anyAttribute` attributes.
42 pub any_attributes_type: IdentPath,
43}
44
45impl MetaData<'_> {
46 /// Whether the passed `flags` intersect with the generator flags set in
47 /// the configuration, or not.
48 #[inline]
49 #[must_use]
50 pub fn check_generator_flags(&self, flags: GeneratorFlags) -> bool {
51 self.flags.intersects(flags)
52 }
53}
54
55impl Deref for MetaData<'_> {
56 type Target = MetaTypes;
57
58 fn deref(&self) -> &Self::Target {
59 self.types
60 }
61}