Env

Trait Env 

Source
pub trait Env {
    type GetVariableError;
    type AssignVariableError;

    // Required methods
    fn get_variable(
        &self,
        name: &str,
    ) -> Result<Option<&str>, Self::GetVariableError>;
    fn assign_variable(
        &mut self,
        name: &str,
        value: String,
        location: Range<usize>,
    ) -> Result<(), Self::AssignVariableError>;
}
Expand description

Interface for accessing variables during evaluation

This crate does not implement any mechanism for storing variables. The caller of eval must provide an implementation of this trait, which is used to access variables that appear in the evaluated expression.

Required Associated Types§

Source

type GetVariableError

Object returned on a variable access error

Source

type AssignVariableError

Object returned on an assignment error

Required Methods§

Source

fn get_variable( &self, name: &str, ) -> Result<Option<&str>, Self::GetVariableError>

Returns the value of the specified variable.

This function must return:

  • Ok(Some(v)) if the variable is defined and has the value v,
  • Ok(None) if the variable is not defined, or
  • Err(error) if an error occurs.
Source

fn assign_variable( &mut self, name: &str, value: String, location: Range<usize>, ) -> Result<(), Self::AssignVariableError>

Assigns a new value to the specified variable.

The location parameter is the index range to the evaluated expression where the assignment appears.

Implementations on Foreign Types§

Source§

impl Env for BTreeMap<String, String>

Source§

impl Env for HashMap<String, String>

Implementors§