From 95ba627a9c5e4e6e1d79f7aaff1854eb831511b4 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 17 Jan 2024 23:54:52 +0100 Subject: hand context on to Function trait --- src/commonsense.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/commonsense.rs') diff --git a/src/commonsense.rs b/src/commonsense.rs index df688fb..4570109 100644 --- a/src/commonsense.rs +++ b/src/commonsense.rs @@ -40,7 +40,8 @@ pub fn tan(a: Complex) -> Complex { macro_rules! commonsense_functions { {$($x:expr => $y:expr), *} => { { - let mut h : HashMap> = HashMap::new(); + use std::sync::Arc; + let mut h : HashMap> = HashMap::new(); h.extend(functions!{ "sqrt" => &crate::commonsense::sqrt, "sin" => &crate::commonsense::sin, @@ -48,7 +49,7 @@ macro_rules! commonsense_functions { "tan" => &crate::commonsense::tan }); $( - h.insert($x.to_string(), Box::new($y)); + h.insert($x.to_string(), Arc::new($y)); )* h } @@ -59,11 +60,11 @@ macro_rules! commonsense_functions { macro_rules! commonsense_operations { {$($x:expr => $y:expr), *} => { vec![ - Operation::new('+', Box::new(&crate::commonsense::add)), - Operation::new('-', Box::new(&crate::commonsense::sub)), - Operation::new('*', Box::new(&crate::commonsense::mul)), - Operation::new('/', Box::new(&crate::commonsense::div)), - Operation::new('^', Box::new(&crate::commonsense::pow)) + Operation::new('+', crate::commonsense::add), + Operation::new('-', crate::commonsense::sub), + Operation::new('*', crate::commonsense::mul), + Operation::new('/', crate::commonsense::div), + Operation::new('^', crate::commonsense::pow) $( Operation::new($x, Box::new($y)), )*] -- cgit v1.2.3-70-g09d2