diff --git a/crates/neon/src/types_impl/extract/container.rs b/crates/neon/src/types_impl/extract/container.rs index 3b0da6ec4..67497b52d 100644 --- a/crates/neon/src/types_impl/extract/container.rs +++ b/crates/neon/src/types_impl/extract/container.rs @@ -22,7 +22,7 @@ impl Container for RefCell { } } -impl<'cx, T: Container + 'static> TryFromJs<'cx> for &'cx RefCell { +impl<'cx, T: 'static> TryFromJs<'cx> for &'cx RefCell { type Error = RustTypeExpected>; fn try_from_js( diff --git a/package-lock.json b/package-lock.json index 97c4532b5..b6617da57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6066,7 +6066,7 @@ } }, "pkgs/create-neon": { - "version": "0.5.2", + "version": "0.6.0", "license": "MIT", "dependencies": { "@neon-rs/manifest": "^0.2.1", diff --git a/test/napi/lib/container.js b/test/napi/lib/container.js new file mode 100644 index 000000000..03257ccff --- /dev/null +++ b/test/napi/lib/container.js @@ -0,0 +1,17 @@ +const addon = require(".."); +const { expect } = require("chai"); +const assert = require("chai").assert; + +describe("container", function () { + it("can produce and consume a RefCell", function () { + const cell = addon.createStringRefCell("my sekret mesij"); + const s = addon.readStringRefCell(cell); + assert.strictEqual("my sekret mesij", s); + }); + + it("concatenates a RefCell with a String", function () { + const cell = addon.createStringRefCell("hello"); + const s = addon.stringRefCellConcat(cell, " world"); + assert.strictEqual("hello world", s); + }); +}); diff --git a/test/napi/src/js/container.rs b/test/napi/src/js/container.rs new file mode 100644 index 000000000..addb083f7 --- /dev/null +++ b/test/napi/src/js/container.rs @@ -0,0 +1,16 @@ +use std::cell::RefCell; + +#[neon::export] +fn create_string_ref_cell(s: String) -> RefCell { + RefCell::new(s) +} + +#[neon::export] +fn read_string_ref_cell(s: &RefCell) -> String { + s.borrow().clone() +} + +#[neon::export] +fn string_ref_cell_concat(lhs: &RefCell, rhs: String) -> String { + lhs.borrow().clone() + &rhs +} diff --git a/test/napi/src/lib.rs b/test/napi/src/lib.rs index 3568e7842..df5835077 100644 --- a/test/napi/src/lib.rs +++ b/test/napi/src/lib.rs @@ -12,6 +12,7 @@ mod js { pub mod bigint; pub mod boxed; pub mod coercions; + pub mod container; pub mod date; pub mod errors; pub mod export;