use super::{Expr, ExprEvaluator};
use crate::err::*;
use crate::eval::*;
#[derive(Debug, Clone)]
pub struct VariableExpr {
pub name: String,
}
impl Expr for VariableExpr {
fn resolve(
&self,
index: Index,
evaluation: &mut dyn ExprEvaluator,
) -> Result<ValueOrReference, ErrorKind> {
evaluation.resolve_variable(index, self.name.clone())
}
fn traverse(
&self,
_evaluation: &dyn ExprEvaluator,
expression: Index,
_name: &Indexer,
) -> Result<Option<ValueOrReference>, ErrorKind> {
Err(ErrorKind::DependenciesNotSatisfied {
indices: vec![expression],
})
}
}
impl From<String> for VariableExpr {
fn from(name: String) -> Self {
VariableExpr { name }
}
}
impl From<&str> for VariableExpr {
fn from(name: &str) -> Self {
VariableExpr {
name: name.to_string(),
}
}
}