use super::Functions;
use crate::common::value::Value;
use crate::eval::scope::Vars;
use smol_str::SmolStr;
#[derive(Debug, Clone, Default)]
pub struct Env<'f> {
pub(super) variables: Vars,
pub(super) functions: Option<&'f Functions>,
}
impl Env<'static> {
pub fn new() -> Self {
Env {
variables: Vars::default(),
functions: None,
}
}
}
impl<'f> Env<'f> {
pub fn with_functions(functions: &'f Functions) -> Self {
Env {
variables: Vars::default(),
functions: Some(functions),
}
}
pub fn set(mut self, name: impl Into<SmolStr>, value: impl Into<Value>) -> Self {
self.variables.insert(name.into(), value.into());
self
}
pub fn insert(&mut self, name: impl Into<SmolStr>, value: impl Into<Value>) -> Option<Value> {
self.variables.insert(name.into(), value.into())
}
}