Remove unbox/cast step in eval
This commit is contained in:
@@ -24,7 +24,7 @@ fn main() {
|
||||
engine.register_fn("update", TestStruct::update);
|
||||
engine.register_fn("new_ts", TestStruct::new);
|
||||
|
||||
if let Ok(result) = engine.eval("var x = new_ts(); x.update(); x").unwrap().downcast::<TestStruct>() {
|
||||
if let Ok(result) = engine.eval::<TestStruct>("var x = new_ts(); x.update(); x") {
|
||||
println!("result: {}", result.x); // prints 1001
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@ use rhai::Engine;
|
||||
fn main() {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
if let Ok(result) = engine.eval("40 + 2").unwrap().downcast::<i32>() {
|
||||
println!("Answer: {}", *result); // prints 42
|
||||
if let Ok(result) = engine.eval::<i32>("40 + 2") {
|
||||
println!("Answer: {}", result); // prints 42
|
||||
}
|
||||
}
|
@@ -5,9 +5,9 @@ fn main() {
|
||||
let mut engine = Engine::new();
|
||||
let mut scope: Scope = Vec::new();
|
||||
|
||||
if let Ok(_) = engine.eval_with_scope(&mut scope, "var x = 4 + 5") { } else { assert!(false); }
|
||||
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "var x = 4 + 5") { } else { assert!(false); }
|
||||
|
||||
if let Ok(result) = engine.eval_with_scope(&mut scope, "x").unwrap().downcast::<i32>() {
|
||||
if let Ok(result) = engine.eval_with_scope::<i32>(&mut scope, "x") {
|
||||
println!("result: {}", result);
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ fn main() {
|
||||
let mut contents = String::new();
|
||||
|
||||
if let Ok(_) = f.read_to_string(&mut contents) {
|
||||
match engine.eval(&contents) {
|
||||
match engine.eval::<()>(&contents) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {println!("Error: {:?}", e)}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ fn main() {
|
||||
|
||||
engine.register_fn("add", add);
|
||||
|
||||
if let Ok(result) = engine.eval("add(40, 2)").unwrap().downcast::<i32>() {
|
||||
println!("Answer: {}", *result); // prints 42
|
||||
if let Ok(result) = engine.eval::<i32>("add(40, 2)") {
|
||||
println!("Answer: {}", result); // prints 42
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user