pub struct Worker { /* private fields */ }Expand description
Core interpreter entry point
Implementations§
source§impl Worker
impl Worker
sourcepub fn new(mixin: HashMap<String, Object>, timeout: f64, lang: Language) -> Self
pub fn new(mixin: HashMap<String, Object>, timeout: f64, lang: Language) -> Self
Configure and initialize a new worker
Examples found in repository?
examples/basic.rs (line 14)
5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let code = "print('Hello, World');".to_string();
// your customized built-in values and rust functions
let mixin = HashMap::from([
("print".into(), Object::Rust(print))
]);
// init the worker with mixin, set to no timeout and English mode
let mut main = Worker::new(mixin, 0.0, Language::EN);
if let Err(e) = main.exec(code) {
println!("{}", e)
}
}sourcepub fn exec(&mut self, code: String) -> Result<Summary, Error>
pub fn exec(&mut self, code: String) -> Result<Summary, Error>
Execute code and flush the global variable scope
Examples found in repository?
examples/basic.rs (line 15)
5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let code = "print('Hello, World');".to_string();
// your customized built-in values and rust functions
let mixin = HashMap::from([
("print".into(), Object::Rust(print))
]);
// init the worker with mixin, set to no timeout and English mode
let mut main = Worker::new(mixin, 0.0, Language::EN);
if let Err(e) = main.exec(code) {
println!("{}", e)
}
}Auto Trait Implementations§
impl Freeze for Worker
impl RefUnwindSafe for Worker
impl Send for Worker
impl Sync for Worker
impl Unpin for Worker
impl UnwindSafe for Worker
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