| Crates.io | mquickjs-rs |
| lib.rs | mquickjs-rs |
| version | 0.2.0 |
| created_at | 2025-12-24 20:49:08.650438+00 |
| updated_at | 2025-12-24 23:02:40.895384+00 |
| description | Safe, idiomatic Rust wrapper for the MicroQuickJS engine |
| homepage | |
| repository | https://github.com/fcoury/mquickjs-rs |
| max_upload_size | |
| id | 2003827 |
| size | 75,714 |
Safe, idiomatic Rust wrapper for the MicroQuickJS engine.
cargo add mquickjs-rs
Or in Cargo.toml:
mquickjs-rs = "0.2.0"
use mquickjs_rs::{Context, Runtime, Value};
let runtime = Runtime::new().expect("runtime should initialize");
let ctx = runtime.context().expect("context should initialize");
let sum = ctx.eval_i32("1 + 2 + 3", "example").expect("eval should succeed");
assert_eq!(sum, 6);
ctx.register_fn("echo", |args: &[Value<'_>]| Ok(args[0]))
.expect("register should succeed");
let echoed = ctx
.eval_string("echo('hello')", "example")
.expect("eval should succeed");
assert_eq!(echoed, "hello");
use mquickjs_rs::{Context, FromValue, IntoValue, Runtime};
let runtime = Runtime::new().expect("runtime should initialize");
let ctx = runtime.context().expect("context should initialize");
let value = 42i32.into_value(&ctx).expect("convert into JS");
let result = i32::from_value(value).expect("convert back");
assert_eq!(result, 42);
use mquickjs_rs::{Array, Context, Object, Runtime};
let runtime = Runtime::new().expect("runtime should initialize");
let ctx = runtime.context().expect("context should initialize");
let obj_value = ctx.eval("({})", "example").expect("eval should succeed");
let obj = Object::from_value(&ctx, obj_value).expect("object should wrap");
obj.set("name", "mquickjs").expect("set should succeed");
let name: String = obj.get("name").expect("get should succeed");
assert_eq!(name, "mquickjs");
let array_value = ctx.eval("[]", "example").expect("eval should succeed");
let array = Array::from_value(&ctx, array_value).expect("array should wrap");
array.push(1i32).expect("push should succeed");
let first: i32 = array.get(0).expect("get should succeed");
assert_eq!(first, 1);
use mquickjs_rs::{Context, Persistent, Runtime};
let runtime = Runtime::new().expect("runtime should initialize");
let ctx = runtime.context().expect("context should initialize");
let value = ctx.eval("'hello'", "example").expect("eval should succeed");
let persistent = Persistent::new(&ctx, value).expect("persist should succeed");
let roundtrip = persistent.to_value().to_string().expect("to_string");
assert_eq!(roundtrip, "hello");
../../mquickjs/README.md for engine limitations.MIT