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: impl Into<String>) -> &mut Trait
pub fn new_trait(&mut self, name: impl Into<String>) -> &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: impl Into<String>) -> &mut Enum
pub fn new_enum(&mut self, name: impl Into<String>) -> &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.
sourcepub fn raw(&mut self, val: impl Into<String>) -> &mut Self
pub fn raw(&mut self, val: impl Into<String>) -> &mut Self
Push a raw string to the scope.
This string will be included verbatim in the formatted string.
sourcepub fn new_type_alias(
&mut self,
name: impl Into<String>,
target: impl Into<String>
) -> &mut TypeAlias
pub fn new_type_alias(
&mut self,
name: impl Into<String>,
target: impl Into<String>
) -> &mut TypeAlias
Push a new TypeAlias
, returning a mutable reference to it.
sourcepub fn push_type_alias(&mut self, item: TypeAlias) -> &mut Self
pub fn push_type_alias(&mut self, item: TypeAlias) -> &mut Self
Push an TypeAlias
.