napi-rs

A framework for building compiled Node.js add-ons in Rust via Node-API

OTHER License

Downloads
6.9M
Stars
5.4K
Committers
119

Bot releases are hidden (Show)

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 1 year ago

2.14.8 (2023-02-16)

Bug Fixes

  • cli: always generate typedef file even native code never changes (#1489) (7281f53)
napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

Error::new API enhancement

Error::new now support passing status: AsRef<str> and message: ToString

pub enum CustomError {
  NapiError(Error<Status>),
  Panic,
}

impl AsRef<str> for CustomError {
  fn as_ref(&self) -> &str {
    match self {
      CustomError::Panic => "Panic",
      CustomError::NapiError(e) => e.status.as_ref(),
    }
  }
}

#[napi]
pub fn custom_status_code() -> Result<(), CustomError> {
  Err(Error::new(CustomError::Panic, "don't panic"))
}
test('custom status code in Error', (t) => {
  t.throws(() => customStatusCode(), {
    code: 'Panic',
  })
})

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.11.1

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

Spread tuple arguments in ThreadsafeFunction

#[napi]
pub fn accept_threadsafe_function_tuple_args(func: ThreadsafeFunction<(u32, bool, String)>) {
  thread::spawn(move || {
    func.call(
      Ok((1, false, "NAPI-RS".into())),
      ThreadsafeFunctionCallMode::NonBlocking,
    );
  });
}

⬇️⬇️⬇️⬇️⬇️⬇️⬇️

export function acceptThreadsafeFunctionTupleArgs(func: (err: Error | null, arg0: number, arg1: boolean, arg2: string) => any): void

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.11.0

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 1 year ago

2.14.7 (2023-02-08)

Bug Fixes

  • cli: JS bindgen file now respects destDir (#1481) (cb529d2)
napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.16

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/[email protected]@2.10.15

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 1 year ago

2.14.6 (2023-02-02)

Note: Version bump only for package @napi-rs/cli

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.1

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.14

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 1 year ago

2.14.5 (2023-01-29)

Bug Fixes

  • cli: upload GitHub assets issue (a302c9c)
napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.13

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.12

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Background

Electron disallowed the create_external_xxx API since electron@21: https://www.electronjs.org/blog/v8-memory-cage
NAPI-RS will fallback to use create_buffer_copy if napi_create_external_buffer return the napi_no_external_buffers_allowed status.

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.11

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

Highlights

ThreadsafeFunction as params and object fields

#[napi]
pub fn accept_callback(callback: ThreadsafeFunction<u32>) {
  std::thread::spawn(move || {
    callback.call(200);
  });
}

⬇️⬇️⬇️⬇️⬇️

export function acceptCallback(callback: (err: Error | null, value: number) -> any)

Disable ToNapiValue for Object

With the object_to_js = false filed, the ThreadsafeFunction could be set as an Object field.

#[napi(object, object_to_js = false)]
pub struct Options {
  pub enable_jsx: bool,
  pub on_data: ThreadsafeFunction<Vec<u8>>,
}

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/[email protected]@2.10.0

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/[email protected]@2.10.10

napi-rs - @napi-rs/[email protected]

Published by Brooooooklyn over 1 year ago

2.14.4 (2023-01-20)

Bug Fixes

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Background

Electron disallowed the create_external_xxx API since electron@21: https://www.electronjs.org/blog/v8-memory-cage
NAPI-RS will fallback to use create_buffer_copy if napi_create_external_buffer return the napi_no_external_buffers_allowed status.

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.9

napi-rs - [email protected]

Published by Brooooooklyn over 1 year ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.2.3

napi-rs - [email protected]

Published by Brooooooklyn almost 2 years ago

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.8