Crate quickjs_rs
source ·Expand description
quick-js is a a Rust wrapper for QuickJS, a new Javascript engine by Fabrice Bellard.
It enables easy and straight-forward execution of modern Javascript from Rust.
Limitations
- Building on Windows requires the
x86_64-pc-windows-gnu
toolchain
Quickstart:
use quickjs_rs::{Context, JsValue};
let context = Context::new().unwrap();
// Eval.
let value = context.eval("1 + 2").unwrap();
assert_eq!(value, JsValue::Int(3));
let value = context.eval_as::<String>(" var x = 100 + 250; x.toString() ").unwrap();
assert_eq!(&value, "350");
// Callbacks.
context.add_callback("myCallback", |a: i32, b: i32| a + b).unwrap();
context.eval(r#"
// x will equal 30
var x = myCallback(10, 20);
"#).unwrap();
Modules
- Javascript console integration. See the ConsoleBackend trait for more info.
Structs
- A wrapper around Vec
, used for vararg callbacks. - A value holding JavaScript BigInt type
- Context is a wrapper around a QuickJS Javascript context. It is the primary way to interact with the runtime.
- A builder for Context.
Enums
- Error on context creation.
- Error on Javascript execution.
- A value that can be (de)serialized to/from the quickjs runtime.
- Error during value conversion.
Traits
- The Callback trait is implemented for functions/closures that can be used as callbacks in the JS runtime.