pub struct Module {
pub name: String,
/* private fields */
}
Expand description
Defines a module.
Fields
name: String
Module name
Implementations
sourceimpl Module
impl Module
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.
sourcepub fn attr(&mut self, attribute: impl Into<String>) -> &mut Self
pub fn attr(&mut self, attribute: impl Into<String>) -> &mut Self
Add an attribute to the 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.
sourcepub fn get_module<Q: ?Sized>(&self, name: &Q) -> Option<&Module>where
String: PartialEq<Q>,
pub fn get_module<Q: ?Sized>(&self, name: &Q) -> Option<&Module>where
String: PartialEq<Q>,
Returns a reference to a module if it is exists in this scope.
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>,
Returns a mutable reference to a module if it is exists in this scope.
sourcepub fn get_or_new_module(&mut self, name: &str) -> &mut Module
pub fn get_or_new_module(&mut self, name: &str) -> &mut Module
Returns a mutable reference to a module, creating it if it does not exist.
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.
sourcepub fn new_struct(&mut self, name: &str) -> &mut Struct
pub fn new_struct(&mut self, name: &str) -> &mut Struct
Push a new struct definition, returning a mutable reference to it.
sourcepub fn push_struct(&mut self, item: Struct) -> &mut Self
pub fn push_struct(&mut self, item: Struct) -> &mut Self
Push a structure definition
sourcepub fn new_fn(&mut self, name: &str) -> &mut Function
pub fn new_fn(&mut self, name: &str) -> &mut Function
Push a new function definition, returning a mutable reference to it.
sourcepub fn new_enum(&mut self, name: &str) -> &mut Enum
pub fn new_enum(&mut self, name: &str) -> &mut Enum
Push a new enum definition, returning a mutable reference to it.
sourcepub fn new_impl(&mut self, target: &str) -> &mut Impl
pub fn new_impl(&mut self, target: &str) -> &mut Impl
Push a new impl
block, returning a mutable reference to it.
sourcepub fn push_trait(&mut self, item: Trait) -> &mut Self
pub fn push_trait(&mut self, item: Trait) -> &mut Self
Push a trait definition