Skip to content

refactor!(napi): arguments tuple behavior#2401

Merged
Brooooooklyn merged 6 commits intonapi-rs:mainfrom
scylladb-zpp-2024-javascript-driver:main
Jan 2, 2025
Merged

refactor!(napi): arguments tuple behavior#2401
Brooooooklyn merged 6 commits intonapi-rs:mainfrom
scylladb-zpp-2024-javascript-driver:main

Conversation

@adespawn
Copy link
Copy Markdown
Contributor

This PR introduces the following changes:

  1. Refactor FromNapiValue trait for tuple to clean up the logic (Code behavior should remain the same)
  2. [API BREAKING] Change of API for calling callbacks with multiple arguments. This change is necessary for the next change.
  3. Implementation of ToNapiValue trait for tuple.

More details is in specific commit description.

Code behavior should remain the same, with much less copy-pasting of the same code.
Additionally, this commit adds a unit tests for test for FromNapiValue
for tuple trait which appears to be currently missing.
Rewrite the macro to reduce the size of expanded code of the macro
(from 4088 to 2429 lines). Although this is a minor change,
this may help reduce the size of compiled library.
Removes the need for keeping mutable variable, as its only assigned once.
This commit introduces new type FnArgs,
that is created with the goal of distinguishing between
calling JS function from rust with tuple as argument
and calling with multiple arguments.

Currently there is no possibility to add ToNapiValue value,
as tuple is used to call callback functions with more than one
argument from rust.

With this change, callbacks with multiple arguments,
should be called, with converting tuple of argument
into FnArgs struct, either by calling into() on such
tuple, or by creating FnArgs struct directly.
Updated the macro for generating typescript types,
to correctly handle FnArgs struct. This is now treated
as passthrough type and generates the output from the
type inside of FnArgs struct.
With the changes to callback calling API, it's now possible
to safely add this change. This change allows to pass tuple
from rust code to JS to match the existing FromNapiValue trait
currently existing in the library.
@Brooooooklyn Brooooooklyn changed the title Changes to tuples behavior refactor!(napi): arguments tuple behavior Jan 2, 2025
@Brooooooklyn Brooooooklyn merged commit b4b74d6 into napi-rs:main Jan 2, 2025
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Feb 3, 2025
<!-- Thank you for contributing! -->

### Description
1. the modification because napi-rs/napi-rs#2401
<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Feb 3, 2025
<!-- Thank you for contributing! -->

### Description
1. the modification because napi-rs/napi-rs#2401
<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
IWANABETHATGUY added a commit to rolldown/rolldown that referenced this pull request Feb 3, 2025
<!-- Thank you for contributing! -->

### Description
1. the modification because napi-rs/napi-rs#2401
<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants