CodeGen

Trait CodeGen 

Source
pub trait CodeGen {
Show 24 methods // Required methods fn output_language(&self) -> OutputLanguage; fn to_method_name_case(&self, name: &str) -> String; fn to_field_name_case(&self, name: &str) -> String; fn to_type_name_case(&self, s: &str) -> String; fn source_formatter( &self, formatter: Vec<String>, ) -> Result<Box<dyn SourceFormatter>>; // Provided methods fn init( &mut self, model: Option<&Model>, lc: &LanguageConfig, output_dir: Option<&Path>, renderer: &mut Renderer<'_>, ) -> Result<(), Error> { ... } fn generate_file( &mut self, w: &mut Writer, model: &Model, file_config: &OutputFile, params: &BTreeMap<String, Value>, ) -> Result<Bytes> { ... } fn init_file( &mut self, w: &mut Writer, model: &Model, file_config: &OutputFile, params: &BTreeMap<String, Value>, ) -> Result<()> { ... } fn write_source_file_header( &mut self, w: &mut Writer, model: &Model, params: &BTreeMap<String, Value>, ) -> Result<()> { ... } fn declare_types( &mut self, w: &mut Writer, model: &Model, params: &BTreeMap<String, Value>, ) -> Result<()> { ... } fn write_services( &mut self, w: &mut Writer, model: &Model, params: &BTreeMap<String, Value>, ) -> Result<()> { ... } fn finalize(&mut self, w: &mut Writer) -> Result<Bytes> { ... } fn write_documentation( &mut self, w: &mut Writer, _id: &Identifier, text: &str, ) { ... } fn write_comment(&mut self, w: &mut Writer, kind: CommentKind, line: &str) { ... } fn write_ident(&self, w: &mut Writer, id: &Identifier) { ... } fn write_ident_with_suffix( &mut self, w: &mut Writer, id: &Identifier, suffix: &str, ) -> Result<()> { ... } fn has_rename_trait(&self, traits: &AppliedTraits) -> Option<String> { ... } fn get_file_extension(&self) -> &'static str { ... } fn to_method_name( &self, method_id: &Identifier, method_traits: &AppliedTraits, ) -> String { ... } fn to_field_name( &self, member_id: &Identifier, member_traits: &AppliedTraits, ) -> Result<String, Error> { ... } fn get_field_name_and_ser_name( &self, field: &NumberedMember, ) -> Result<(String, String)> { ... } fn op_dispatch_name(&self, id: &Identifier) -> String { ... } fn full_dispatch_name( &self, service_id: &Identifier, method_id: &Identifier, ) -> String { ... } fn format(&mut self, files: Vec<PathBuf>, lc: &LanguageConfig) -> Result<()> { ... }
}
Expand description

A Codegen is used to generate source for a Smithy Model The generator will invoke these functions (in order)

  • init()
  • write_source_file_header()
  • declare_types()
  • write_services()
  • finalize()

Required Methods§

Source

fn output_language(&self) -> OutputLanguage

Returns current output language

Source

fn to_method_name_case(&self, name: &str) -> String

Convert method name to its target-language-idiomatic case style

Source

fn to_field_name_case(&self, name: &str) -> String

Convert field name to its target-language-idiomatic case style

Source

fn to_type_name_case(&self, s: &str) -> String

Convert type name to its target-language-idiomatic case style

Source

fn source_formatter( &self, formatter: Vec<String>, ) -> Result<Box<dyn SourceFormatter>>

Provided Methods§

Source

fn init( &mut self, model: Option<&Model>, lc: &LanguageConfig, output_dir: Option<&Path>, renderer: &mut Renderer<'_>, ) -> Result<(), Error>

Initialize code generator and renderer for language output.j This hook is called before any code is generated and can be used to initialize code generator and/or perform additional processing before output files are created.

Source

fn generate_file( &mut self, w: &mut Writer, model: &Model, file_config: &OutputFile, params: &BTreeMap<String, Value>, ) -> Result<Bytes>

This entrypoint drives output-file-specific code generation. This default implementation invokes init_file, write_source_file_header, declare_types, write_services, and finalize. The return value is Bytes containing the data that should be written to the output file.

Source

fn init_file( &mut self, w: &mut Writer, model: &Model, file_config: &OutputFile, params: &BTreeMap<String, Value>, ) -> Result<()>

Perform any initialization required prior to code generation for a file model may be used to check model metadata id is a tag from codegen.toml that indicates which source file is to be written namespace is the namespace in the model to generate

Source

fn write_source_file_header( &mut self, w: &mut Writer, model: &Model, params: &BTreeMap<String, Value>, ) -> Result<()>

generate the source file header

Source

fn declare_types( &mut self, w: &mut Writer, model: &Model, params: &BTreeMap<String, Value>, ) -> Result<()>

Write declarations for simple types, maps, and structures

Source

fn write_services( &mut self, w: &mut Writer, model: &Model, params: &BTreeMap<String, Value>, ) -> Result<()>

Write service declarations and implementation stubs

Source

fn finalize(&mut self, w: &mut Writer) -> Result<Bytes>

Complete generation and return the output bytes

Source

fn write_documentation(&mut self, w: &mut Writer, _id: &Identifier, text: &str)

Write documentation for item

Source

fn write_comment(&mut self, w: &mut Writer, kind: CommentKind, line: &str)

Writes single-line comment beginning with ’// ’ Can be overridden if more specific kinds are needed

Source

fn write_ident(&self, w: &mut Writer, id: &Identifier)

Source

fn write_ident_with_suffix( &mut self, w: &mut Writer, id: &Identifier, suffix: &str, ) -> Result<()>

append suffix to type name, for example “Game”, “Context” -> “GameContext”

Source

fn has_rename_trait(&self, traits: &AppliedTraits) -> Option<String>

Source

fn get_file_extension(&self) -> &'static str

returns file extension of source files for this language

Source

fn to_method_name( &self, method_id: &Identifier, method_traits: &AppliedTraits, ) -> String

Convert method name to its target-language-idiomatic case style implementors should override to_method_name_case

Source

fn to_field_name( &self, member_id: &Identifier, member_traits: &AppliedTraits, ) -> Result<String, Error>

Convert field name to its target-language-idiomatic case style implementors should override to_field_name_case

Source

fn get_field_name_and_ser_name( &self, field: &NumberedMember, ) -> Result<(String, String)>

Source

fn op_dispatch_name(&self, id: &Identifier) -> String

The operation name used in dispatch, from method The default implementation is provided and should not be overridden

Source

fn full_dispatch_name( &self, service_id: &Identifier, method_id: &Identifier, ) -> String

The full operation name with service prefix The default implementation is provided and should not be overridden

Source

fn format(&mut self, files: Vec<PathBuf>, lc: &LanguageConfig) -> Result<()>

After code generation has completed for all files, this method is called once per output language to allow code formatters to run. The files parameter contains a list of all files written or updated.

Implementors§

Source§

impl<'model> CodeGen for GoCodeGen<'model>

Source§

impl<'model> CodeGen for RustCodeGen<'model>