Node.js N-API for Rust! [work in progress]

Build Status

High-level N-API bindings for Node.js addons written in Rust.

Warning: this is a proof-of-concept implementation that's not intended for use yet. The project is under initial phase of development, the API is a quite sketchy and is going to be refactored heavily. If you are interested in contributing, though, it is super welcome!

The project is covered by a Code of Conduct.

Crates

Example

Check out https://github.com/aqrln/napi-rs/tree/master/example to see the full source code and project structure of this example. (TODO: initialize the module from Rust too).

lib.rs

```rust

[macro_use]

extern crate napi;

[macro_use]

extern crate napi_derive;

use napi::{NapiEnv, NapiNumber, NapiResult, NapiUndefined};

[derive(NapiArgs)]

struct HelloArgs;

fn hello<'a>(env: &'a NapiEnv, _: &HelloArgs) -> NapiResult> { println!("Hello from the Rust land!"); NapiUndefined::new(env) }

[derive(NapiArgs)]

struct AddArgs<'a> { first: NapiNumber<'a>, second: NapiNumber<'a>, }

fn add<'a>(env: &'a NapiEnv, args: &AddArgs<'a>) -> NapiResult> { let first = args.first.toi32()?; let second = args.second.toi32()?; NapiNumber::from_i32(env, first + second) }

napicallback!(examplehello, hello); napicallback!(exampleadd, add); ```

example.js

```javascript 'use strict';

const addon = require('./build/Release/example.node');

addon.hello(); console.log(addon.add(1, 2)); ```