pub struct Module {
pub name: String,
/* private fields */
}
Expand description
Defines a module.
Fields§
§name: String
Module name
Implementations§
Source§impl 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 new_module(&mut self, name: &str) -> &mut Self
pub fn new_module(&mut self, name: &str) -> &mut Self
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<&Self>
pub fn get_module<Q: ?Sized>(&self, name: &Q) -> Option<&Self>
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 Self>
pub fn get_module_mut<Q: ?Sized>(&mut self, name: &Q) -> Option<&mut Self>
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 Self
pub fn get_or_new_module(&mut self, name: &str) -> &mut Self
Returns a mutable reference to a module, creating it if it does not exist.
Sourcepub fn push_module(&mut self, item: Self) -> &mut Self
pub fn push_module(&mut self, item: Self) -> &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