Returning a reference #1142
-
I'm looking into implementing the CSS Typed OM API for Parcel CSS. This has a complex hierarchy of objects, with fields that include other objects, etc. One thing I ran into is that it currently doesn't seem easy (or possible?) to have a getter or method return the same instance of an object each time it is called. I tried returning a reference, but this seems to currently panic: napi-rs/crates/backend/src/codegen/struct.rs Lines 102 to 112 in 4f422b6 I saw the Say I have the following structs: #[napi]
struct Foo {
bar: Bar
}
#[napi]
struct Bar {
baz: u32
}
#[napi]
impl Foo {
#[napi(getter)]
pub fn bar(&self) -> ??? {
self.bar
}
} How can I make |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The |
Beta Was this translation helpful? Give feedback.
The
2.3.0
released a new feature: Reference API.I think it's perfectly suitable for your scenario. I haven't had time to write the documentation for this feature but you can see the real-world example: https://github.com/Brooooooklyn/simple-git/blob/main/src/repo.rs#L211.
@devongovett