xsd-parser 1.5.2

Rust code generator for XML schema files
Documentation
use std::ops::Deref;

use proc_macro2::Ident as Ident2;

use crate::config::RendererFlags;
use crate::models::{code::IdentPath, data::DataTypes};

/// Meta data of the render process.
///
/// Contains different information and data that is useful during the code
/// rendering process.
#[derive(Debug)]
pub struct MetaData<'types> {
    /// Data types generated by the [`Generator`](crate::Generator).
    pub types: &'types DataTypes<'types>,

    /// Flags that controls the behavior of the renderer.
    pub flags: RendererFlags,

    /// Traits the renderer should derive all types from.
    pub derive: Vec<IdentPath>,

    /// List of traits that should be implemented by dynamic types.
    pub dyn_type_traits: Vec<IdentPath>,

    /// Name of the `alloc` crate.
    pub alloc_crate: Ident2,

    /// Name of the `xsd-parser-types` crate.
    pub xsd_parser_types: Ident2,
}

impl MetaData<'_> {
    /// Whether the passed `flags` intersect with the renderer flags set in
    /// the configuration, or not.
    #[must_use]
    pub fn check_renderer_flags(&self, flags: RendererFlags) -> bool {
        self.flags.intersects(flags)
    }
}

impl<'types> Deref for MetaData<'types> {
    type Target = DataTypes<'types>;

    fn deref(&self) -> &Self::Target {
        self.types
    }
}