Move lookup_function back onto Evaluator
THe problem was that we were borrowing the output of the inner HashMap, if we clone it we don't borrow anything
This commit is contained in:
parent
1ffbeb6472
commit
dcf89aa429
10
src/eval.rs
10
src/eval.rs
@ -21,10 +21,6 @@ impl Funcmap {
|
|||||||
let map = HashMap::new();
|
let map = HashMap::new();
|
||||||
Funcmap { map: map }
|
Funcmap { map: map }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_function(&self, name: String) -> Option<Function> {
|
|
||||||
self.map.get(&name).map(|x| x.clone())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Evaluator {
|
pub struct Evaluator {
|
||||||
@ -70,6 +66,9 @@ impl Evaluator {
|
|||||||
self.funcmap.map.insert(name, function);
|
self.funcmap.map.insert(name, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lookup_function(&self, name: String) -> Option<Function> {
|
||||||
|
self.funcmap.map.get(&name).map(|x| x.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Evaluable {
|
trait Evaluable {
|
||||||
@ -209,8 +208,7 @@ impl Evaluator {
|
|||||||
|
|
||||||
fn reduce_call(&mut self, name: String, arguments: Vec<Expression>) -> Expression {
|
fn reduce_call(&mut self, name: String, arguments: Vec<Expression>) -> Expression {
|
||||||
use parser::Expression::*;
|
use parser::Expression::*;
|
||||||
let x = self.funcmap.lookup_function(name);
|
let function = match self.lookup_function(name) {
|
||||||
let function = match x {
|
|
||||||
Some(func) => func,
|
Some(func) => func,
|
||||||
None => return Null
|
None => return Null
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user