use std::rc::Rc; use super::{Environment, Node, Precedence}; pub type ConstantValue = f64; #[derive(Clone, Debug, PartialEq, PartialOrd)] pub struct Constant { value: ConstantValue, } impl Node for Constant { fn evaluate(&self, _: &mut super::Environment) -> Result, String> { Ok(Rc::new(self.clone().into())) } fn as_string(&self, _env: Option<&Environment>) -> String { self.value.to_string() } fn precedence(&self) -> Precedence { Precedence::Primary } } impl Constant { pub fn new(value: ConstantValue) -> Self { Self { value } } pub fn get_value(&self) -> ConstantValue { self.value } pub fn set_value(&mut self, value: ConstantValue) { self.value = value; } }