xsd_parser/models/data/enumeration.rs
1use std::borrow::Cow;
2
3use proc_macro2::{Ident as Ident2, Literal, TokenStream};
4
5use crate::models::data::{ConstrainsData, PathData};
6use crate::models::meta::{EnumerationMeta, EnumerationMetaVariant};
7use crate::pipeline::renderer::ValueRendererBox;
8
9/// Contains additional information for the rendering process of a
10/// [`MetaTypeVariant::Enumeration`](crate::models::meta::MetaTypeVariant::Enumeration)
11/// type.
12#[derive(Debug)]
13pub struct EnumerationData<'types> {
14 /// Reference to the original type information.
15 pub meta: Cow<'types, EnumerationMeta>,
16
17 /// Code generator data for the constrains of the type.
18 pub constrains: ConstrainsData<'types>,
19
20 /// The identifier of the rendered type.
21 pub type_ident: Ident2,
22
23 /// List of variants of this enumeration.
24 pub variants: Vec<EnumerationDataVariant<'types>>,
25
26 /// List of traits that needs to be implemented by this type.
27 pub trait_impls: Vec<TokenStream>,
28
29 /// Simple base type of this enumeration.
30 pub simple_base_type: Option<PathData>,
31}
32
33/// Represents a enumeration variant used by [`EnumerationData`].
34#[derive(Debug)]
35pub struct EnumerationDataVariant<'types> {
36 /// Reference to the original type information.
37 pub meta: Cow<'types, EnumerationMetaVariant>,
38
39 /// Name of the attribute as string.
40 pub s_name: String,
41
42 /// Name of the attribute as byte string literal.
43 pub b_name: Literal,
44
45 /// Value renderer to render either a constant or a getter function for
46 /// the value of this variant represented at its simple base type.
47 pub value: EnumerationVariantValue,
48
49 /// Name of this variant.
50 pub variant_ident: Ident2,
51
52 /// Target type of this variant.
53 pub target_type: Option<PathData>,
54
55 /// Additional attributes that will be added to the variant.
56 pub extra_attributes: Vec<TokenStream>,
57}
58
59/// Value renderer to render either a constant or a getter function for
60/// the value of this variant represented at its simple base type.
61#[derive(Debug)]
62pub enum EnumerationVariantValue {
63 /// No value renderer, because the simple base type of this enumeration is not supported.
64 None,
65
66 /// Value renderer to render a byte string literal for the value of this variant.
67 ByteLiteral(Ident2, ValueRendererBox),
68
69 /// Value renderer to render a constant for the value of this variant.
70 Constant(Ident2, ValueRendererBox),
71}