Struct rust_codegen::Scope
source · [−]pub struct Scope { /* private fields */ }
Expand description
Defines a scope.
A scope contains modules, types, etc.
Implementations
sourceimpl 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> 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_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 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.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Scope
impl Send for Scope
impl Sync for Scope
impl Unpin for Scope
impl UnwindSafe for Scope
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