pub struct Interpreter { /* private fields */ }Implementations§
Source§impl Interpreter
impl Interpreter
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/example.rs (line 6)
5fn main() {
6 let mut interp = Interpreter::new();
7 interp.eval("x = 10").unwrap();
8 interp.eval("y = 20").unwrap();
9 let val = interp
10 .eval("[max(x + y * 2, x * 2 - y), abs(x - y), x**2]")
11 .unwrap();
12 println!("{}", val); // 50
13
14 let context = HashMap::from([("x".to_string(), Value::Number(10.0))]);
15 let val = interp.eval_with_context("x + 1", &context).unwrap();
16 println!("{}", val); // 11
17
18 let val = interp.eval_boolean("x + 1").unwrap();
19 println!("{}", val); // true
20}Sourcepub fn eval(&mut self, code: &str) -> Result<Value, EvalError>
pub fn eval(&mut self, code: &str) -> Result<Value, EvalError>
Examples found in repository?
examples/example.rs (line 7)
5fn main() {
6 let mut interp = Interpreter::new();
7 interp.eval("x = 10").unwrap();
8 interp.eval("y = 20").unwrap();
9 let val = interp
10 .eval("[max(x + y * 2, x * 2 - y), abs(x - y), x**2]")
11 .unwrap();
12 println!("{}", val); // 50
13
14 let context = HashMap::from([("x".to_string(), Value::Number(10.0))]);
15 let val = interp.eval_with_context("x + 1", &context).unwrap();
16 println!("{}", val); // 11
17
18 let val = interp.eval_boolean("x + 1").unwrap();
19 println!("{}", val); // true
20}Sourcepub fn eval_with_context(
&self,
code: &str,
context: &HashMap<String, Value>,
) -> Result<Value, EvalError>
pub fn eval_with_context( &self, code: &str, context: &HashMap<String, Value>, ) -> Result<Value, EvalError>
Examples found in repository?
examples/example.rs (line 15)
5fn main() {
6 let mut interp = Interpreter::new();
7 interp.eval("x = 10").unwrap();
8 interp.eval("y = 20").unwrap();
9 let val = interp
10 .eval("[max(x + y * 2, x * 2 - y), abs(x - y), x**2]")
11 .unwrap();
12 println!("{}", val); // 50
13
14 let context = HashMap::from([("x".to_string(), Value::Number(10.0))]);
15 let val = interp.eval_with_context("x + 1", &context).unwrap();
16 println!("{}", val); // 11
17
18 let val = interp.eval_boolean("x + 1").unwrap();
19 println!("{}", val); // true
20}Sourcepub fn eval_boolean(&self, code: &str) -> Result<bool, EvalError>
pub fn eval_boolean(&self, code: &str) -> Result<bool, EvalError>
Examples found in repository?
examples/example.rs (line 18)
5fn main() {
6 let mut interp = Interpreter::new();
7 interp.eval("x = 10").unwrap();
8 interp.eval("y = 20").unwrap();
9 let val = interp
10 .eval("[max(x + y * 2, x * 2 - y), abs(x - y), x**2]")
11 .unwrap();
12 println!("{}", val); // 50
13
14 let context = HashMap::from([("x".to_string(), Value::Number(10.0))]);
15 let val = interp.eval_with_context("x + 1", &context).unwrap();
16 println!("{}", val); // 11
17
18 let val = interp.eval_boolean("x + 1").unwrap();
19 println!("{}", val); // true
20}Auto Trait Implementations§
impl Freeze for Interpreter
impl !RefUnwindSafe for Interpreter
impl !Send for Interpreter
impl !Sync for Interpreter
impl Unpin for Interpreter
impl !UnwindSafe for Interpreter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more