Skip to main content

xsd_parser/models/data/
union.rs

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