Remove lifetime from Engine.

This commit is contained in:
Stephen Chung
2020-04-16 23:31:48 +08:00
parent 4f2350734f
commit f8e9d66a0b
8 changed files with 95 additions and 99 deletions

View File

@@ -81,18 +81,18 @@ fn test_side_effects_command() -> Result<(), EvalAltResult> {
#[test]
fn test_side_effects_print() -> Result<(), EvalAltResult> {
use std::sync::Arc;
use std::sync::RwLock;
let result = RwLock::new(String::from(""));
let result = Arc::new(RwLock::new(String::from("")));
{
let mut engine = Engine::new();
let mut engine = Engine::new();
// Override action of 'print' function
engine.on_print(|s| result.write().unwrap().push_str(s));
// Override action of 'print' function
let logger = result.clone();
engine.on_print(move |s| logger.write().unwrap().push_str(s));
engine.consume("print(40 + 2);")?;
}
engine.consume("print(40 + 2);")?;
assert_eq!(*result.read().unwrap(), "42");
Ok(())