0

For some reason, I can't use JsBox. I am using the 0.8.2 crate I get the flowing error

unresolved import neon::types::JsBox

Nadsah
  • 109
  • 1
  • 9
  • Looking at the [documentation of the neon crate, version 0.8.2](https://docs.rs/neon/0.8.2/neon/), there is no `JsBox` anywhere. – Sven Marnach May 21 '21 at 11:55
  • I see that the documentation of the `types` module still mentions `JsBox`, but the link is dead. It probably existed in an earlier version and has been removed. – Sven Marnach May 21 '21 at 11:57
  • it seems, that it still exists in [this version](https://docs.rs/neon/0.8.2-napi/neon/types/struct.JsBox.html) – Nadsah May 21 '21 at 12:19
  • Looks like you [need to enable the `napi-1` feature](https://docs.rs/neon/0.8.2-napi/src/neon/types/mod.rs.html#76-77). – Sven Marnach May 21 '21 at 12:29
  • how do I do that? – Nadsah May 21 '21 at 12:31
  • [How do you enable a Rust “crate feature”?](https://stackoverflow.com/questions/58480205/how-do-you-enable-a-rust-crate-feature) – Sven Marnach May 21 '21 at 12:36

1 Answers1

1

According to this, neon::types::JsBox seems to be only available with the new N-API backend. You can find a migration guide here. This is probably the most relevant part:

Enabling the N-API backend

To enable the N-API backend, you need to:

  1. Remove build.rs from the project directory and build = "build.rs" from the Cargo.toml. The N-API backend does not require a Cargo build script.
  2. Disable the default features (for now, the default features select the legacy > backend) by setting default-features = false; and
  3. Enable the appropriate feature flag in your Cargo.toml to select the N-API version you need support for (each N-API version N uses the feature flag "napi-N", for example "napi-4" for N-API version 4).

As a rule, you should choose the oldest version of N-API that has the APIs you need. (We will be adding N-API version requirements to the Neon API docs to make this clearer in the future.) You can consult the official N-API feature matrix to see which N-API versions come with various versions of Node.

[dependencies.neon]
version = "0.8.2"
default-features = false
features = ["napi-4"]
Elias Holzmann
  • 3,216
  • 2
  • 17
  • 33