aboutsummaryrefslogtreecommitdiff
path: root/src/commonsense.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-01-17 23:54:52 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2024-01-17 23:54:52 +0100
commit95ba627a9c5e4e6e1d79f7aaff1854eb831511b4 (patch)
tree177d58d387143d644ce7ad2c97eb30032e226533 /src/commonsense.rs
parent9cc61497ed8a2336f33407d3262181e4ac3b46cb (diff)
hand context on to Function trait
Diffstat (limited to 'src/commonsense.rs')
-rw-r--r--src/commonsense.rs15
1 files changed, 8 insertions, 7 deletions
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<String, Box<dyn Function>> = HashMap::new();
+ use std::sync::Arc;
+ let mut h : HashMap<String, Arc<dyn Function>> = 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)),
)*]