-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
I'm pretty new to Rust and JNI, so sorry if this is a bad question.
Is there a way to store a raw pointer to a struct as a field?
For example, I have a complex structure named Runtime. This has properties that won't serialize to Java, but that's fine, I just want a reference to it and use its functions on the Rust side. I was thinking I could add runtime as a field using JObject:
#[derive(Signature, TryIntoJavaValue, IntoJavaValue, TryFromJavaValue)]
#[package()]
pub struct JniRunner<'env: 'borrow, 'borrow> {
#[instance]
raw: AutoLocal<'env, 'borrow>,
#[field]
runtime: Field<'env, 'borrow, JObject<'env>>,
}
However, I'm not clear on how to convert my Runtime struct into a JObject using this package's version of JNI. I was thinking I could do something like below, but JNI 0.19.0 doesn't have the from_raw method on JObject:
let raw_ptr = Box::into_raw(Box::new(Runtime {}));
self.runtime.set(unsafe { JObject::from_raw(raw_ptr as jobject) });
Is there a better way to store a raw pointer to a complex struct in robusta?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels