[−][src]Struct codegen::Scope
Defines a scope.
A scope contains modules, types, etc...
Methods
impl Scope
[src]
pub fn new() -> Self
[src]
Returns a new scope
pub fn import(&mut self, path: &str, ty: &str) -> &mut Import
[src]
Import a type into the scope.
This results in a new use
statement being added to the beginning of
the scope.
pub fn new_module(&mut self, name: &str) -> &mut Module
[src]
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.
pub fn get_module_mut<Q: ?Sized>(&mut self, name: &Q) -> Option<&mut Module> where
String: PartialEq<Q>,
[src]
String: PartialEq<Q>,
Returns a mutable reference to a module if it is exists in this scope.
pub fn get_module<Q: ?Sized>(&self, name: &Q) -> Option<&Module> where
String: PartialEq<Q>,
[src]
String: PartialEq<Q>,
Returns a mutable reference to a module if it is exists in this scope.
pub fn get_or_new_module(&mut self, name: &str) -> &mut Module
[src]
Returns a mutable reference to a module, creating it if it does not exist.
pub fn push_module(&mut self, item: Module) -> &mut Self
[src]
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.
pub fn new_struct(&mut self, name: &str) -> &mut Struct
[src]
Push a new struct definition, returning a mutable reference to it.
pub fn push_struct(&mut self, item: Struct) -> &mut Self
[src]
Push a struct definition
pub fn new_trait(&mut self, name: &str) -> &mut Trait
[src]
Push a new trait definition, returning a mutable reference to it.
pub fn push_trait(&mut self, item: Trait) -> &mut Self
[src]
Push a trait definition
pub fn new_enum(&mut self, name: &str) -> &mut Enum
[src]
Push a new struct definition, returning a mutable reference to it.
pub fn push_enum(&mut self, item: Enum) -> &mut Self
[src]
Push a structure definition
pub fn new_impl(&mut self, target: &str) -> &mut Impl
[src]
Push a new impl
block, returning a mutable reference to it.
pub fn push_impl(&mut self, item: Impl) -> &mut Self
[src]
Push an impl
block.
pub fn raw(&mut self, val: &str) -> &mut Self
[src]
Push a raw string to the scope.
This string will be included verbatim in the formatted string.
pub fn to_string(&self) -> String
[src]
Return a string representation of the scope.
pub fn fmt(&self, fmt: &mut Formatter) -> Result
[src]
Formats the scope using the given formatter.
Trait Implementations
impl Clone for Scope
[src]
fn clone(&self) -> Scope
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Scope
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,