Use ? operator in tests.

This commit is contained in:
Stephen Chung
2020-03-09 21:09:53 +08:00
parent 63482d5a79
commit 5b5fd162be
6 changed files with 51 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
use rhai::{Engine, RegisterFn};
use rhai::{Engine, EvalAltResult, RegisterFn};
#[derive(Clone)]
struct TestStruct {
@@ -15,7 +15,7 @@ impl TestStruct {
}
}
fn main() {
fn main() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
engine.register_type::<TestStruct>();
@@ -23,7 +23,9 @@ fn main() {
engine.register_fn("update", TestStruct::update);
engine.register_fn("new_ts", TestStruct::new);
if let Ok(result) = engine.eval::<TestStruct>("let x = new_ts(); x.update(); x") {
println!("result: {}", result.x); // prints 1001
}
let result = engine.eval::<TestStruct>("let x = new_ts(); x.update(); x")?;
println!("result: {}", result.x); // prints 1001
Ok(())
}