Struct rust_codegen::Module
source · [−]pub struct Module {
pub name: String,
/* private fields */
}
Expand description
Defines a module.
Fields
name: String
The module’s name.
Implementations
sourceimpl Module
impl Module
sourcepub fn scope(&mut self) -> &mut Scope
pub fn scope(&mut self) -> &mut Scope
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());
sourcepub fn import(&mut self, path: &str, ty: &str) -> &mut Self
pub fn import(&mut self, path: &str, ty: &str) -> &mut Self
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");
sourcepub fn new_module(&mut self, name: &str) -> &mut Module
pub fn new_module(&mut self, name: &str) -> &mut 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");
sourcepub fn get_module_mut<Q: ?Sized>(&mut self, name: &Q) -> Option<&mut Module> where
String: PartialEq<Q>,
pub fn get_module_mut<Q: ?Sized>(&mut self, name: &Q) -> Option<&mut Module> where
String: PartialEq<Q>,
sourcepub fn get_or_new_module(&mut self, name: &str) -> &mut Module
pub fn get_or_new_module(&mut self, name: &str) -> &mut Module
sourcepub fn push_module(&mut self, item: Module) -> &mut Self
pub fn push_module(&mut self, item: Module) -> &mut Self
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);
sourcepub fn new_struct(&mut self, name: &str) -> &mut Struct
pub fn new_struct(&mut self, name: &str) -> &mut Struct
sourcepub fn push_struct(&mut self, item: Struct) -> &mut Self
pub fn push_struct(&mut self, item: Struct) -> &mut Self
sourcepub fn push_trait(&mut self, item: Trait) -> &mut Self
pub fn push_trait(&mut self, item: Trait) -> &mut Self
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Module
impl Send for Module
impl Sync for Module
impl Unpin for Module
impl UnwindSafe for Module
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more