xsd_parser/generator/renderer/
mod.rs1use std::fmt::Debug;
4
5use inflector::Inflector;
6use quote::format_ident;
7
8use crate::{
9 code::{IdentPath, Module},
10 types::Module as TypesModule,
11};
12
13use super::{data::TypeData, Config, Context};
14
15mod defaults;
16mod namespace_const;
17mod quick_xml;
18mod types;
19mod with_namespace_trait;
20
21pub use self::defaults::DefaultsRenderer;
22pub use self::namespace_const::NamespaceConstantsRenderer;
23pub use self::quick_xml::{QuickXmlDeserializeRenderer, QuickXmlSerializeRenderer};
24pub use self::types::TypesRenderer;
25pub use self::with_namespace_trait::WithNamespaceTraitRenderer;
26
27pub trait Renderer: Debug {
34 fn initialize(&mut self, config: &mut Config<'_>) {
38 let _config = config;
39 }
40
41 fn render_type(&mut self, ctx: &mut Context<'_, '_>, ty: &TypeData<'_>) {
45 let _cxt = ctx;
46 let _ty = ty;
47 }
48
49 fn finish(&mut self, config: &Config<'_>, module: &mut Module) {
54 let _config = config;
55 let _module = module;
56 }
57}
58
59impl TypesModule {
60 pub(super) fn make_ns_const(&self) -> IdentPath {
61 let ident = format_ident!(
62 "NS_{}",
63 self.name
64 .as_ref()
65 .map_or_else(|| String::from("DEFAULT"), ToString::to_string)
66 .to_screaming_snake_case()
67 );
68
69 IdentPath::from_parts([], ident)
70 }
71}