From 77cf9aa7535a1d9481f0bd3caeea26e2b85c5019 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 17 Jan 2024 22:30:02 +0100 Subject: migrate from f64 to own complex --- src/context.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/context.rs') diff --git a/src/context.rs b/src/context.rs index 12bea6b..47be92b 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,11 +1,12 @@ 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, + vars: HashMap, funcs: HashMap>, } @@ -19,7 +20,7 @@ impl Context { self } - pub fn with_variables(mut self, vars: HashMap) -> Self { + pub fn with_variables(mut self, vars: HashMap) -> Self { self.vars = vars; self } @@ -33,7 +34,7 @@ impl Context { &self.ops } - pub fn variable_mut(&mut self, name: &str) -> Option<&mut f64> { + pub fn variable_mut(&mut self, name: &str) -> Option<&mut Complex> { self.vars.get_mut(name) } @@ -41,11 +42,26 @@ impl Context { self.funcs.get_mut(name) } - pub fn variable(&self, name: &str) -> Option<&f64> { + 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 + } + }; +} + -- cgit v1.2.3-70-g09d2