quickjs-rusty

Crates.ioquickjs-rusty
lib.rsquickjs-rusty
version0.6.3
sourcesrc
created_at2024-06-19 18:05:50.500428
updated_at2024-07-07 16:59:49.789524
descriptionA rusty QuickJS (QuickJS-NG) Javascript engine wrapper, and more.
homepage
repositoryhttps://github.com/Icemic/quickjs-rusty
max_upload_size
id1277244
size228,956
Icemic (Icemic)

documentation

https://docs.rs/quickjs-rusty

README

quickjs-rusty

Crates.io docs.rs

QuickJS is a small and embeddable Javascript engine by Fabrice Bellard and Charlie Gordon. It supports the ES2023 specification including modules, asynchronous generators, proxies and BigInt.
Quickjs-NG is one of the most active forks of QuickJS, and it is maintained by the community focused on reigniting the project.

This crate allows you to easily access and use all the features of QuickJS from Rust. It also provides robust Rust-JS type conversion and interoperability capabilities.

Quickstart

[dependencies]
quickjs-rusty = "0.6.3"
use quickjs_rusty::{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();

Note: This project is derived from quickjs-rs, but it has undergone significant restructuring. It features a completely different code structure and functional design compared to the original project.

Optional Features

The crate supports the following features:

  • serde: (default enabled). enable serde method from_js and to_js to transform between Rust types and js value in quickjs context. It should compatible with serde_json but not tested yet. See more on the example.
  • chrono: (default enabled). chrono integration
    • adds a JsValue::Date variant that can be (de)serialized to/from a JS Date
  • bigint: (default enabled). arbitrary precision integer support via num-bigint

Installation

By default, quickjs is bundled with the libquickjs-sys crate and automatically compiled, assuming you have the appropriate dependencies.

Windows Support

quickjspp-rs can be used under target x86_64-pc-windows-msvc,

System installation

To use the system installation, without the bundled feature, first install the required dependencies, and then compile and install quickjspp.

You then need to disable the bundled feature in the libquickjs-sys crate to force using the system version.

Commit count: 299

cargo fmt