xsd_parser/models/data/union.rs
1use proc_macro2::{Ident as Ident2, Literal, TokenStream};
2
3use crate::models::{
4 data::{ConstrainsData, PathData},
5 meta::{UnionMeta, UnionMetaType},
6};
7
8/// Contains additional information for the rendering process of a
9/// [`MetaTypeVariant::Union`](crate::models::meta::MetaTypeVariant::Union) type.
10#[derive(Debug)]
11pub struct UnionData<'types> {
12 /// Reference to the original type information.
13 pub meta: &'types UnionMeta,
14
15 /// Code generator data for the constrains of the type.
16 pub constrains: ConstrainsData<'types>,
17
18 /// The identifier of the rendered type.
19 pub type_ident: Ident2,
20
21 /// List of variants contained in this union.
22 pub variants: Vec<UnionTypeVariant<'types>>,
23
24 /// List of traits that needs to be implemented by this type.
25 pub trait_impls: Vec<TokenStream>,
26}
27
28/// Type variant used in [`UnionData`].
29#[derive(Debug)]
30pub struct UnionTypeVariant<'types> {
31 /// Reference to the original type information.
32 pub meta: &'types UnionMetaType,
33
34 /// Name of the attribute as string.
35 pub s_name: String,
36
37 /// Name of the attribute as byte string literal.
38 pub b_name: Literal,
39
40 /// The type that is stored by the this variant.
41 pub target_type: PathData,
42
43 /// Identifier of this variant.
44 pub variant_ident: Ident2,
45
46 /// Additional attributes that will be added to the variant.
47 pub extra_attributes: Vec<TokenStream>,
48}