From 1713618d4cc0194674f91fd2d24ef2de88f21784 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 18 Jan 2024 18:29:10 +0100 Subject: create small iced demo --- src/function.rs | 68 --------------------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 src/function.rs (limited to 'src/function.rs') diff --git a/src/function.rs b/src/function.rs deleted file mode 100644 index 4daebf4..0000000 --- a/src/function.rs +++ /dev/null @@ -1,68 +0,0 @@ -use crate::{complex::Complex, context::Context}; - -pub struct FunctionArgument { - args : Vec, -} - -impl FunctionArgument { - pub fn new(args: Vec) -> Self { - Self { args } - } - - pub fn get(&self, i : usize) -> Complex { - self.args[i] - } - - pub fn len(&self) -> usize { - self.args.len() - } - - pub fn is_empty(&self) -> bool { - self.args.len() == 0 - } - - pub fn data(&self) -> &[Complex] { - &self.args - } -} - -pub trait Function { - fn eval(&self, args: FunctionArgument, ctx: &Context) -> Result; -} - -#[macro_export] -macro_rules! functions { - {$($x:expr => $y:expr), *} => { - { - let mut h : HashMap> = HashMap::new(); - $( - h.insert($x.to_string(), Arc::new($y)); - )* - h - } - }; -} - - -// Some default implementations -impl Function for T -where - T: Fn(Complex) -> Complex, -{ - fn eval(&self, args: FunctionArgument, _ctx: &Context) -> Result { - if args.len() == 1 { - Ok(self(args.get(0))) - } else { - Err("too many arguments".to_string()) - } - } -} - - -pub struct EmptyFunction {} - -impl Function for EmptyFunction { - fn eval(&self, _args: FunctionArgument, _ctx: &Context) -> Result { - Err("function not implemented in this scope".to_string()) - } -} -- cgit v1.2.3-70-g09d2