pub struct Module {
pub code: TokenStream,
pub usings: BTreeMap<String, bool>,
pub modules: BTreeMap<String, Module>,
}Expand description
Manages the code that is generated for a specific module.
This type stores the generated code, the related using directives as well as any sub-module for a specific module generated by the code generator.
Fields§
§code: TokenStreamThe actual code that is manages by this module.
usings: BTreeMap<String, bool>A set of using directives this module needs.
modules: BTreeMap<String, Module>A map of sub-modules contained inside this module.
Implementations§
Source§impl Module
impl Module
Sourcepub fn append(&mut self, code: TokenStream) -> &mut Self
pub fn append(&mut self, code: TokenStream) -> &mut Self
Append the passed code to this module code.
Sourcepub fn prepend(&mut self, code: TokenStream) -> &mut Self
pub fn prepend(&mut self, code: TokenStream) -> &mut Self
Prepend the passed code to this module code.
Sourcepub fn usings<I>(&mut self, anonymous: bool, usings: I) -> &mut Self
pub fn usings<I>(&mut self, anonymous: bool, usings: I) -> &mut Self
Add using directives to the set of this module.
Sourcepub fn module<T>(&self, ident: T) -> Option<&Module>
pub fn module<T>(&self, ident: T) -> Option<&Module>
Get a reference to a sub-module identified by the passed ident.
If the module does not exist None is returned.
Sourcepub fn module_mut<T>(&mut self, ident: T) -> &mut Module
pub fn module_mut<T>(&mut self, ident: T) -> &mut Module
Get a mutable reference to a sub-module identified by the passed ident.
If the module does not exist it will be created.
Sourcepub fn to_code(&self, tokens: &mut TokenStream, sub_modules: SubModules)
pub fn to_code(&self, tokens: &mut TokenStream, sub_modules: SubModules)
Write the module to the passed token stream.
This method writes the current module to the passed token stream. The
sub_modules parameter defines how the sub-modules of this module will
be rendered.
Sourcepub fn write_to_files<P>(&self, directory: P) -> Result<(), IoError>
pub fn write_to_files<P>(&self, directory: P) -> Result<(), IoError>
Sourcepub fn write_to_files_with<F, E>(&self, f: F) -> Result<(), E>
pub fn write_to_files_with<F, E>(&self, f: F) -> Result<(), E>
Write the code of the different sub-modules by using the passed
function f.
This will split up the current module into it’s sub modules and
passes the generated code for each module to the passed function f.
§Errors
Forwards the error raised by f.