You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use neon::prelude::*;#[neon::main]fnmain(mutcx:ModuleContext) -> NeonResult<()>{
cx.export_class::<Blake3Hash>("Hasher");Ok(())}pubstructBlake3Hash{hasher: blake3::Hasher,}implBlake3Hash{}implDefaultforBlake3Hash{fndefault() -> Self{Self{hasher: blake3::Hasher::new()}}}implFinalizeforBlake3Hash{}
My cargo.toml is created by create neon:
[package]
name = "blakish"
version = "0.1.0"
license = "ISC"
edition = "2018"
exclude = ["index.node"]
[lib]
crate-type = ["cdylib"]
[dependencies]
blake3 = "1.2"
[dependencies.neon]
version = "0.9"
default-features = false
features = ["napi-6"]
However on cx.export_class::<Blake3Hash>("Hasher"); I am getting an error the method is not found because it is apparently only for the legacy-runtime.
#[cfg(feature = "legacy-runtime")]
/// Convenience method for exporting a Neon class constructor from a module.
pub fn export_class<T: Class>(&mut self, key: &str) -> NeonResult<()> {
let constructor = T::constructor(self)?;
self.exports.set(self, key, constructor)?;
Ok(())
}
Is there still a way to export a class with napi? Or do we have to wrap it all in functions now with JsBox?
The text was updated successfully, but these errors were encountered:
Correct. Classes are only implemented in the legacy runtime. Their design is not compatible with with web workers and were not easily ported. There is proposal to add them (neon-bindings/rfcs#43), but it's not being currently worked on.
In the meantime, JsBox provides everything you need when combined with some JavaScript glue code. The idea is that store your Rust data in a JsBox and create a wrapper class in JavaScript that passes it to functions, either as the first argument or bound to this.
I am trying to create a very small test binding:
My cargo.toml is created by create neon:
However on
cx.export_class::<Blake3Hash>("Hasher");
I am getting an error the method is not found because it is apparently only for the legacy-runtime.Is there still a way to export a class with napi? Or do we have to wrap it all in functions now with JsBox?
The text was updated successfully, but these errors were encountered: