3

napi-rs Docs

 3 years ago
source link: https://napi.rs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

NAPI-RS is a minimal library for building pre-compiled NodeJS addons in Rust.

lib.rs
#[js_function(1)]
fn fibonacci(ctx: CallContext) -> Result<JsNumber> {
let n = ctx.get::<JsNumber>(0)?.try_into()?;
ctx.env.create_int64(fibonacci_native(n))
index.js
function hello() {
let result = fibonacci(10000)
console.log(result)
return result

Features

🚀 Bring native performance for NodeJS

👷‍♂️ Memory safe, guaranteed by Rust compiler

⚡️ Zero copy data interactive between Rust & NodeJS

⚙️ Parallelism in few lines

Well tested

LintLinux N-API@3Linux muslmacOS/Windows/Linux x64Linux-aarch64Windows i686

Support matrix

NodeJS

Node10Node12Node14Node15✓✓✓✓

Platform support

✅ Means official tested in napi-rs repo.
- Means no official NodeJS release.

i686x64aarch64armWindows✅✅--macOS-✅✅-Linux-✅✅✅Linux musl-✅--FreeBSD-✅--Android--✅-

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK