use crate::function::Function; use crate::operation::Operation; use crate::complex::Complex; use std::collections::HashMap; #[derive(Default)] pub struct Context { ops: Vec, vars: HashMap, funcs: HashMap>, } impl Context { pub fn new() -> Self { Self::default() } pub fn with_operations(mut self, ops: Vec) -> Self { self.ops = ops; self } pub fn with_variables(mut self, vars: HashMap) -> Self { self.vars = vars; self } pub fn with_functions(mut self, funcs: HashMap>) -> Self { self.funcs = funcs; self } pub fn operations(&self) -> &Vec { &self.ops } pub fn variable_mut(&mut self, name: &str) -> Option<&mut Complex> { self.vars.get_mut(name) } pub fn function_mut(&mut self, name: &str) -> Option<&mut Box> { self.funcs.get_mut(name) } pub fn variable(&self, name: &str) -> Option<&Complex> { self.vars.get(name) } #[allow(clippy::borrowed_box)] pub fn function(&self, name: &str) -> Option<&Box> { self.funcs.get(name) } } #[macro_export] macro_rules! variables { {$($x:expr => $y:expr), *} => { { let mut h : HashMap = HashMap::new(); $( h.insert($x.to_string(), $y); )* h } }; }