postscriptum 0.1.1

Multi-interpreted-language scripting engine for Rust with Rhai and Python backends
Documentation
//! Example: share a single `ThreadSafeEngine` across threads.
//!
//! `ThreadSafeEngine` is a `Clone` wrapper around
//! `Arc<Mutex<Box<dyn ScriptEngine>>>`, so each thread gets its own handle to
//! the same underlying (stateful) engine.

use postscriptum::{EngineType, ThreadSafeEngine, get_engine};
use std::thread;

fn main() -> postscriptum::Result<()> {
    let engine = ThreadSafeEngine::new(get_engine(EngineType::Rhai));
    engine.eval("let x = 0")?;

    let mut handles = Vec::new();
    for i in 0..4 {
        let engine = engine.clone();
        handles.push(thread::spawn(move || {
            engine.eval(&format!("x = x + {i}; x")).unwrap()
        }));
    }

    for handle in handles {
        println!("thread result: {}", handle.join().unwrap());
    }
    Ok(())
}