Struct Scope

Source
pub struct Scope { /* private fields */ }
Expand description

Defines a scope.

A scope contains modules, types, etc.

Implementations§

Source§

impl Scope

Source

pub fn new() -> Self

Returns a new scope.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn new_struct(&mut self, name: &str) -> &mut Struct

Push a new struct definition, returning a mutable reference to it.

Source

pub fn push_struct(&mut self, item: Struct) -> &mut Self

Push a struct definition

Source

pub fn new_fn(&mut self, name: &str) -> &mut Function

Push a new function definition, returning a mutable reference to it.

Source

pub fn push_fn(&mut self, item: Function) -> &mut Self

Push a function definition

Source

pub fn new_trait(&mut self, name: &str) -> &mut Trait

Push a new trait definition, returning a mutable reference to it.

Source

pub fn push_trait(&mut self, item: Trait) -> &mut Self

Push a trait definition

Source

pub fn new_enum(&mut self, name: &str) -> &mut Enum

Push a new struct definition, returning a mutable reference to it.

Source

pub fn push_enum(&mut self, item: Enum) -> &mut Self

Push a structure definition

Source

pub fn new_impl(&mut self, target: &str) -> &mut Impl

Push a new impl block, returning a mutable reference to it.

Source

pub fn push_impl(&mut self, item: Impl) -> &mut Self

Push an impl block.

Source

pub fn raw(&mut self, val: &str) -> &mut Self

Push a raw string to the scope.

This string will be included verbatim in the formatted string.

Source

pub fn to_string(&self) -> String

Return a string representation of the scope.

Source

pub fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the scope using the given formatter.

Trait Implementations§

Source§

impl Clone for Scope

Source§

fn clone(&self) -> Scope

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Scope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnwindSafe for Scope

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.