Struct Module Copy item path Source pub struct Module {
pub name: String ,
}
Expand description Return a new, blank module.
§ Arguments
name
- The name of the module.
§ Examples
use rust_codegen::Module;
let foo_module = Module::new("Foo" );
Returns a mutable reference to the module’s scope.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
println! ("{:?}" , foo_module.scope());
Set the module visibility.
§ Arguments
vis
- The visibility of the module.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.vis("pub" );
Import a type into the module’s scope.
This results in a new use
statement bein added to the beginning of
the module.
§ Arguments
path
- The path to the type to import.
ty
- The type to import.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.import("rust_codegen" , "Module" );
Push a new module definition, returning a mutable reference to it.
§ Panics
Since a module’s name must uniquely identify it within the scope in
which it is defined, pushing a module whose name is already defined
in this scope will cause this function to panic.
In many cases, the get_or_new_module
function is preferrable, as it
will return the existing definition instead.
§ Arguments
name
- The name of the module.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.new_module("Bar" );
Returns a reference to a module if it is exists in this scope.
§ Arguments
name
- The name of the module to get.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.new_module("Bar" );
foo_module.get_module("Bar" );
Returns a mutable reference to a module if it is exists in this scope.
§ Arguments
name
- The name of the module to get.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.new_module("Bar" );
foo_module.get_module("Bar" );
Returns a mutable reference to a module, creating it if it does
not exist.
§ Arguments
name
- The name of the module to get or create if it doesn’t exist.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.get_or_new_module("Bar" );
Push a module definition.
§ Panics
Since a module’s name must uniquely identify it within the scope in
which it is defined, pushing a module whose name is already defined
in this scope will cause this function to panic.
In many cases, the get_or_new_module
function is preferrable, as it will
return the existing definition instead.
§ Arguments
item
- The module to push.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
let mut bar_module = Module::new("Bar" );
foo_module.push_module(bar_module);
Push a new struct definition, returning a mutable reference to it.
§ Arguments
name
- The name of the struct to push.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.new_struct("Bar" );
Push a structure definition.
§ Arguments
item
- The struct definition to push.
§ Examples
use rust_codegen::{Module,Struct};
let mut foo_module = Module::new("Foo" );
let mut bar_struct = Struct::new("Bar" );
foo_module.push_struct(bar_struct);
Push a new function definition, returning a mutable reference to it.
§ Arguments
name
- The name of the function to push.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.new_fn("bar_fn" );
Push a function definition.
§ Arguments
item
- The function definition to push.
§ Examples
use rust_codegen::{Function,Module};
let mut foo_module = Module::new("Foo" );
let mut bar_fn = Function::new("bar_fn" );
foo_module.push_fn(bar_fn);
Push a new enum definition, returning a mutable reference to it.
§ Arguments
name
- The name of the enum.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.new_enum("Bar" );
Push an enum definition.
§ Arguments
item
- The enum definition to push.
§ Examples
use rust_codegen::{Enum,Module};
let mut foo_module = Module::new("Foo" );
let mut bar_enum = Enum::new("Bar" );
foo_module.push_enum(bar_enum);
Push a new impl
block, returning a mutable reference to it.
§ Arguments
target
- The impl block to push.
§ Examples
use rust_codegen::Module;
let mut foo_module = Module::new("Foo" );
foo_module.new_impl("Bar" );
Push an impl
block.
§ Arguments
item
- The impl definition to push.
§ Examples
use rust_codegen::{Impl,Module};
let mut foo_module = Module::new("Foo" );
let mut bar_impl = Impl::new("Bar" );
foo_module.push_impl(bar_impl);
Push a trait definition.
§ Arguments
item
- The trait to push.
§ Examples
use rust_codegen::{Module,Trait};
let mut foo_module = Module::new("Foo" );
let mut bar_trait = Trait::new("Bar" );
foo_module.push_trait(bar_trait);
Formats the module using the given formatter.
§ Arguments
fmt
- The formatter to use.
§ Examples
use rust_codegen::* ;
let mut dest = String::new();
let mut fmt = Formatter::new(&mut dest);
let mut foo_module = Module::new("Foo" );
foo_module.fmt(&mut fmt);
Performs copy-assignment from
source
.
Read more Formats the value using the given formatter.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit
)
Performs copy-assignment from
self
to
dest
.
Read more Returns the argument unchanged.
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From <T> for U
chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.