Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,52 @@ it still gets the benefits of the ABI stability provided by the C API.
When using `node-addon-api` instead of the C APIs, start with the API [docs][]
for `node-addon-api`.

## Rust

Node-API is also accessible from Rust through the [NAPI-RS][] project.
`NAPI-RS` provides safe Rust bindings to Node-API, allowing developers to write
native Node.js modules in Rust while maintaining ABI stability across Node.js
versions. The project offers both low-level bindings that closely mirror the
Node-API C interface and high-level, idiomatic Rust APIs that leverage Rust's
type system and memory safety guarantees.

Similar to the C++ wrapper, `NAPI-RS` simplifies the development process.
For example, creating an object with a property in `NAPI-RS`:

```rust
#[napi(object)]
pub struct MyObject {
foo: String,
}

#[napi]
pub fn create_object() -> MyObject {
MyObject {
foo: "bar".to_string(),
}
}
```

This will automatically generate the following TypeScript definition:

```ts
export interface MyObject {
foo: string;
}

export declare function createObject(): MyObject;
```

The `NAPI-RS` ecosystem includes:

* Build tooling that simplifies the compilation and packaging process
* TypeScript type generation for better IDE support
* Cross-platform compilation support, including `WebAssembly`

When using `NAPI-RS` for Rust-based Node.js addons, refer to the
[NAPI-RS documentation](https://napi.rs) for comprehensive
guides and examples.

The [Node-API Resource](https://nodejs.github.io/node-addon-examples/) offers
an excellent orientation and tips for developers just getting started with
Node-API and `node-addon-api`. Additional media resources can be found on the
Expand Down Expand Up @@ -6744,6 +6790,7 @@ the add-on's file name during loading.
[GYP]: https://gyp.gsrc.io
[GitHub releases]: https://help.github.com/en/github/administering-a-repository/about-releases
[LLVM]: https://llvm.org
[NAPI-RS]: https://github.com/napi-rs/napi-rs
[Native Abstractions for Node.js]: https://github.com/nodejs/nan
[Node-API Media]: https://github.com/nodejs/abi-stable-node/blob/HEAD/node-api-media.md
[Object lifetime management]: #object-lifetime-management
Expand Down
Loading