pub struct Scope { /* private fields */ }
Expand description
Defines a scope.
A scope contains modules, types, etc.
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn import(&mut self, path: &str, ty: &str) -> &mut Import
pub fn import(&mut self, path: &str, ty: &str) -> &mut Import
Import a type into the scope.
This results in a new use
statement being added to the beginning of
the scope.
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_mut<Q: ?Sized>(&mut self, name: &Q) -> Option<&mut Module>
pub fn get_module_mut<Q: ?Sized>(&mut self, name: &Q) -> Option<&mut Module>
Returns a mutable reference to a module if it is exists in this scope.
Sourcepub fn get_module<Q: ?Sized>(&self, name: &Q) -> Option<&Module>
pub fn get_module<Q: ?Sized>(&self, name: &Q) -> Option<&Module>
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 struct 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_trait(&mut self, name: &str) -> &mut Trait
pub fn new_trait(&mut self, name: &str) -> &mut Trait
Push a new trait definition, 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
Sourcepub fn new_enum(&mut self, name: &str) -> &mut Enum
pub fn new_enum(&mut self, name: &str) -> &mut Enum
Push a new struct 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.