Skip to main content

Env

Struct Env 

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

An environment structure.

The environment is used by an interpreter and built-in functions and contains modules, variables, and a stack which are available by methods of the environment. Each stack element has a function module and local variables. Also, the environment has a script directory, a domain, the standard I/O enumerations, and a shared environment. The standard I/O enumerations determine which streams are used to the standard I/O in built-in functions.

Implementations§

Source§

impl Env

Source

pub fn new_with_script_dir_and_domain_and_shared_env( root_mod: Arc<RwLock<ModNode<Value, ()>>>, script_dir: PathBuf, domain: Option<String>, shared_env: Arc<RwLock<SharedEnv>>, ) -> Self

Creates an environment with the path to script directory, the domain, and the shared environment.

Also, this method takes the root module that has the variables and other modules.

Source

pub fn new(root_mod: Arc<RwLock<ModNode<Value, ()>>>) -> Self

Creates an environment.

See new_with_script_dir_and_domain_and_shared_env.

Source

pub fn clone_without_stack(&self) -> Self

Clones the environment without the stack.

Source

pub fn root_mod(&self) -> &Arc<RwLock<ModNode<Value, ()>>>

Returns the root module.

Source

pub fn current_mod(&self) -> &Arc<RwLock<ModNode<Value, ()>>>

Returns the current module.

Source

pub fn mod_idents(&self) -> &[String]

Returns the identifiers of current module.

Source

pub fn stack( &self, ) -> &[(Arc<RwLock<ModNode<Value, ()>>>, BTreeMap<String, Value>)]

Returns the stack.

Source

pub fn script_dir(&self) -> &Path

Returns the path to script directory.

Source

pub fn domain(&self) -> Option<&str>

Returns the domain.

Source

pub fn stdin(&self) -> &Input

Returns the standard input enumeration.

Source

pub fn set_stdin(&mut self, input: Input)

Sets the standart input enumeration.

Source

pub fn stdout(&self) -> &Output

Returns the standard output enumeration.

Source

pub fn set_stdout(&mut self, output: Output)

Sets the standard output enumeration.

Source

pub fn stderr(&self) -> &Output

Returns the standard error enumeration.

Source

pub fn set_stderr(&mut self, output: Output)

Sets the standard error enumeration.

Source

pub fn shared_env(&self) -> &Arc<RwLock<SharedEnv>>

Retunrs the shared environment.

Source

pub fn add_and_push_mod(&mut self, ident: String) -> Result<bool>

Adds an empty module to the current module and then the empty module is set as the current module.

This method adds the empty, sets the empty module as current, and returns true if a module with the identifier doesn’t exist in the current module; otherwise this method returns false.

Source

pub fn pop_mod(&mut self) -> Result<bool>

Sets the parent module of the current module is set as the current module.

This method sets the parent module as current and returns true if the current module has the parent module, otherwise this method returns false.

Source

pub fn add_fun(&self, ident: String, fun: Arc<Fun>) -> Result<bool>

Adds the function.

This method adds the function and returns true if a function or a variable with the identifier doesn’t exist in the current module, otherwise this method returnsfalse.

Source

pub fn push_fun_mod_and_local_vars( &mut self, fun_mod_idents: &[String], args: &[Arg], arg_values: &[Value], ) -> Result<bool>

Pushes the function module and a local variables to the stack for applies the function.

This method pushes the function module and the local variables and returns true if all identifiers of arguments are different, otherwise this method returns false.

Source

pub fn pop_fun_mod_and_local_vars(&mut self)

Removes the last functoin module and the last local varables from stack.

Source

pub fn reset(&mut self) -> Result<()>

Resets the environment.

Source

pub fn var(&self, name: &Name) -> Result<Option<Value>>

Returns the variable value for the variable name if the variable exists, otherwise None.

Source

pub fn set_var(&mut self, name: &Name, value: Value) -> Result<bool>

Sets the variable value for the variable name and returns true if the variable can be set, otherwise this method returns false.

Source

pub fn remove_local_var(&mut self, ident: &String) -> bool

Removes the local variable with the identifier and returns true if the stack isn’t empty, otherwise this method returns false.

Trait Implementations§

Source§

impl Clone for Env

Source§

fn clone(&self) -> Env

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Env

§

impl RefUnwindSafe for Env

§

impl Send for Env

§

impl Sync for Env

§

impl Unpin for Env

§

impl UnsafeUnpin for Env

§

impl UnwindSafe for Env

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more