xsd_parser/pipeline/renderer/
meta.rs

1use std::ops::Deref;
2
3use proc_macro2::Ident as Ident2;
4
5use crate::config::RendererFlags;
6use crate::models::{code::IdentPath, data::DataTypes};
7
8/// Meta data of the render process.
9///
10/// Contains different information and data that is useful during the code
11/// rendering process.
12#[derive(Debug)]
13pub struct MetaData<'types> {
14    /// Data types generated by the [`Generator`](crate::Generator).
15    pub types: &'types DataTypes<'types>,
16
17    /// Flags that controls the behavior of the renderer.
18    pub flags: RendererFlags,
19
20    /// Traits the renderer should derive all types from.
21    pub derive: Vec<Ident2>,
22
23    /// List of traits that should be implemented by dynamic types.
24    pub dyn_type_traits: Vec<IdentPath>,
25
26    /// Name of the `xsd_parser` crate.
27    pub xsd_parser_crate: Ident2,
28}
29
30impl MetaData<'_> {
31    /// Whether the passed `flags` intersect with the renderer flags set in
32    /// the configuration, or not.
33    #[must_use]
34    pub fn check_renderer_flags(&self, flags: RendererFlags) -> bool {
35        self.flags.intersects(flags)
36    }
37}
38
39impl<'types> Deref for MetaData<'types> {
40    type Target = DataTypes<'types>;
41
42    fn deref(&self) -> &Self::Target {
43        self.types
44    }
45}