Skip to content

Commit 7fa33ea

Browse files
committed
docs: improve the README, add symlinks to sub-crates
1 parent dc9709d commit 7fa33ea

File tree

7 files changed

+71
-6
lines changed

7 files changed

+71
-6
lines changed

README.md

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,76 @@
44

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

7-
This project is covered by a [Code of Conduct](CODE_OF_CONDUCT.md).
7+
**Warning**: this is a proof-of-concept implementation that's not intended
8+
for use yet. The project is under initial phase of development, the API is a
9+
quite sketchy and is going to be refactored heavily. If you are interested in
10+
contributing, though, it is super welcome!
11+
12+
The project is covered by a [Code of Conduct][coc].
813

914
## Crates
1015

11-
* `napi-sys`: low-level bindings to N-API generated from
16+
* [`napi-sys`][napi-sys]: low-level bindings to N-API generated from
1217
[`node_api.h`](https://github.com/nodejs/node/blob/master/src/node_api.h)
1318
using [`bindgen`](https://github.com/rust-lang-nursery/rust-bindgen).
14-
* `napi`: high-level and rusty wrappers around `napi-sys`.
15-
* `napi-derive`: contains a procedural macro that allows to construct typesafe
16-
structures that represent function parameters from JavaScript function call
17-
arguments and automatically validate them.
19+
* [`napi`][napi]: high-level and rusty wrappers around `napi-sys`.
20+
* [`napi-derive`][napi-derive]: contains a procedural macro that allows to
21+
construct typesafe structures that represent N-API callback parameters and
22+
automatically validate the arguments that JavaScript code passes in.
23+
24+
## Example
25+
26+
Check out <https://github.com/aqrln/napi-rs/tree/master/example> to see the
27+
full source code and project structure of this example.
28+
29+
### `lib.rs`
30+
31+
```rust
32+
#[macro_use]
33+
extern crate napi;
34+
#[macro_use]
35+
extern crate napi_derive;
36+
37+
use napi::{NapiEnv, NapiNumber, NapiResult, NapiUndefined};
38+
39+
#[derive(NapiArgs)]
40+
struct HelloArgs;
41+
42+
fn hello<'a>(env: &'a NapiEnv, _: &HelloArgs) -> NapiResult<NapiUndefined<'a>> {
43+
println!("Hello from the Rust land!");
44+
NapiUndefined::new(env)
45+
}
46+
47+
#[derive(NapiArgs)]
48+
struct AddArgs<'a> {
49+
first: NapiNumber<'a>,
50+
second: NapiNumber<'a>,
51+
}
52+
53+
fn add<'a>(env: &'a NapiEnv, args: &AddArgs<'a>) -> NapiResult<NapiNumber<'a>> {
54+
let first = args.first.to_i32()?;
55+
let second = args.second.to_i32()?;
56+
NapiNumber::from_i32(env, first + second)
57+
}
58+
59+
napi_callback!(example_hello, hello);
60+
napi_callback!(example_add, add);
61+
```
62+
63+
### `example.js`
64+
65+
```javascript
66+
'use strict';
67+
68+
const addon = require('./build/Release/example.node');
69+
70+
addon.hello();
71+
console.log(addon.add(1, 2));
72+
```
1873

74+
[coc]: https://github.com/aqrln/napi-rs/blob/master/CODE_OF_CONDUCT.md
75+
[napi]: https://crates.io/crates/napi
76+
[napi-derive]: https://crates.io/crates/napi-derive
77+
[napi-sys]: https://crates.io/crates/napi-sys
1978
[travis-badge]: https://travis-ci.org/aqrln/napi-rs.svg?branch=master
2079
[travis-url]: https://travis-ci.org/aqrln/napi-rs

napi-derive/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

napi-derive/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

napi-sys/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

napi-sys/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

napi/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

napi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

0 commit comments

Comments
 (0)