无法从 Neon::types 导入 JsBox

can't import JsBox from Neon::types

由于某些原因,我无法使用 JsBox。我正在使用 0.8.2 crate 我得到了流动错误

未解决的导入问题neon::types::JsBox

根据this, neon::types::JsBox seems to be only available with the new N-API backend. You can find a migration guide here。这可能是最相关的部分:

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"]