napi-rs / napi-rs/napi-rs

pass object/class as parameter

Open
#2,170 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
7.9k
Forks
412
Avg merge
1d 20h
Merged PRs (30d)
61

Description

How can you create a function like this in js?

function a(res) {
  res.setA(42);
}

The only work around i foun was to create a type in rust like this:

#[napi] pub type Test = fn(res: &mut Response);

but has a problem #[napi] can only be applied to a function, struct, enum, const, mod or impl.

What should I do?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no file or test. Start at the #[napi] entry point and trace how Rust parameters are exposed across the Rust/JavaScript boundary; done would be a documented or supported way to pass an object or class-like value to a JavaScript function such as a(res), with coverage for res.setA(42).

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, rust
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.