pub struct Generator {}
Expand description
A Generator is a data-driven wrapper around code generator implementations, There are two main modes of generation: handlebars template-driven, and code-driven. For the latter, you implement a trait CodeGen, which gets callbacks for various parts of the code generation. One parameter to CodeGen is the output file name, which can be used if code is to be generated across several files. (for example, if you want one file to define interfaces and a separate file to define implementation classe). Handlebars-driven code generation may be more well-suited for files such as Makefiles and project config files that don’t need a huge amount of customization, but they can also be used to generate 100% of an interface. You decide!
Implementations§
Source§impl<'model> Generator
impl<'model> Generator
Sourcepub fn gen(
&self,
model: Option<&'model Model>,
config: CodegenConfig,
templates: Vec<(String, String)>,
output_dir: &Path,
defines: Vec<(String, Value)>,
) -> Result<()>
pub fn gen( &self, model: Option<&'model Model>, config: CodegenConfig, templates: Vec<(String, String)>, output_dir: &Path, defines: Vec<(String, Value)>, ) -> Result<()>
Perform code generation on model, iterating through each configured OutputFile. Each file to be generated is either based on a handlebars template, which is generated with the Renderer class, or is generated by an implemented of the CodeGen implementation. Function parameters:
- model - the smithy model
- config - CodeConfig (usually loaded from a codegen.toml file)
- N.B. all relative paths (template dirs and the output_dir parameter) are adjusted to be relative to config.base_dir.
- templates - list of additional templates to register with the handlebars engine (The templates parameter of config is ignored. to use a list of file paths, call templates_from_dir() to load them and generate this parameter)
- output_dir - top-level folder containing all output files
- create - whether the user intends to create a new project (true) or just update (false).
The generator does not check for existence of an output file before overwriting. Usually the
create
flag is set to true for the first pass when project files are created, after which time the project file can be manually edited, and only the main codegen output will be updated. The default (create is false/the flag is unspecified)) changes the fewest files