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§
Sourcetype GetVariableError
type GetVariableError
Object returned on a variable access error
Sourcetype AssignVariableError
type AssignVariableError
Object returned on an assignment error
Required Methods§
Sourcefn get_variable(
&self,
name: &str,
) -> Result<Option<&str>, Self::GetVariableError>
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 valuev,Ok(None)if the variable is not defined, orErr(error)if an error occurs.
Sourcefn assign_variable(
&mut self,
name: &str,
value: String,
location: Range<usize>,
) -> Result<(), Self::AssignVariableError>
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.