aboutsummaryrefslogtreecommitdiff
path: root/src/function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/function.rs')
-rw-r--r--src/function.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/function.rs b/src/function.rs
index 0da4574..126477c 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -1,4 +1,4 @@
-use crate::complex::Complex;
+use crate::{complex::Complex, context::Context};
pub struct FunctionArgument {
args : Vec<Complex>,
@@ -23,16 +23,16 @@ impl FunctionArgument {
}
pub trait Function {
- fn eval(&self, args: FunctionArgument) -> Result<Complex, String>;
+ fn eval(&self, args: FunctionArgument, ctx: &Context) -> Result<Complex, String>;
}
#[macro_export]
macro_rules! functions {
{$($x:expr => $y:expr), *} => {
{
- let mut h : HashMap<String, Box<dyn Function>> = HashMap::new();
+ let mut h : HashMap<String, Arc<dyn Function>> = HashMap::new();
$(
- h.insert($x.to_string(), Box::new($y));
+ h.insert($x.to_string(), Arc::new($y));
)*
h
}
@@ -45,7 +45,7 @@ impl<T> Function for T
where
T: Fn(Complex) -> Complex,
{
- fn eval(&self, args: FunctionArgument) -> Result<Complex, String> {
+ fn eval(&self, args: FunctionArgument, _ctx: &Context) -> Result<Complex, String> {
if args.len() == 1 {
Ok(self(args.get(0)))
} else {
@@ -53,3 +53,12 @@ where
}
}
}
+
+
+pub struct EmptyFunction {}
+
+impl Function for EmptyFunction {
+ fn eval(&self, _args: FunctionArgument, _ctx: &Context) -> Result<Complex, String> {
+ Err("function not implemented in this scope".to_string())
+ }
+}