2 个版本
使用旧 Rust 2015
0.3.1 | 2021年3月11日 |
---|---|
0.3.0 | 2021年3月11日 |
#2098 in 开发工具
15KB
178 行
为 Wilton JavaScript 运行时提供 Rust 模块支持
此库允许使用 Rust 编写 Wilton 原生模块。
许可信息
本项目采用 Apache License 2.0 发布。
变更日志
2021-03-10
- 版本
0.3.1
- 包重命名为
wilton_rusty
- 修复新的编译器警告
- 文档中的 wilton URL 变更
2018-04-14
- 版本
0.2.0
- 支持回调到 JS
2018-03-14
- 版本
0.1.0
- 初始公开版本
lib.rs
:
Rust 模块支持 Wilton JavaScript 运行时
使用示例
// configure Cargo to build a shared library
//[lib]
//crate-type = ["dylib"]
// in lib.rs, import serde and wilton_rusty
//#[macro_use]
//extern crate serde_derive;
//extern crate wilton_rusty;
// ...
// declare input/output structs
#[derive(Deserialize)]
struct MyIn { }
#[derive(Serialize)]
struct MyOut { }
// write a function that does some work
fn hello(obj: MyIn) -> MyOut { }
// register that function inside the `wilton_module_init` function,
// that will be called by Wilton during the Rust module load
#[no_mangle]
pub extern "C" fn wilton_module_init() -> *mut std::os::raw::c_char {
// register a call, error checking omitted
wilton_rusty::register_wiltocall("hello", |obj: MyIn| { hello(obj) });
// return success status to Wilton
wilton_rusty::create_wilton_error(None)
}
请参阅 示例,了解如何从 JavaScript 加载和使用 Rust 库。
依赖关系
~0.5–1MB
~21K SLoC