Struct binary_util::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() -> Scope

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>(&mut self, name: &Q) -> Option<&mut Module>where String: PartialEq<Q>, Q: ?Sized,

Returns a mutable reference to a module if it is exists in this scope.

source

pub fn get_module<Q>(&self, name: &Q) -> Option<&Module>where String: PartialEq<Q>, Q: ?Sized,

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 Scope

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 Scope

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 Scope

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 Scope

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 Scope

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 Scope

Push an impl block.

source

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

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<(), Error>

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<(), Error>

Formats the value using the given formatter. Read more

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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.