#Pass Rust handles to JavaScript (NO serialization)
10 messages · Page 1 of 1 (latest)
Short answer: No, you can only send objects that can be converted to/from json strings.
I'd probably keep the object in Rust and expose the functions you do want to have available in Rust via tauri commands. And if needed write a wrapper class in js by hand (that's how most of Tauri's pre-built js apis work btw)
I see
So treat them as separate systems and pass data via message passing rather than two runtimes in a shared address space?
yeah, exactly
got it. Thanks!
@nocturne yoke sorry to bother you again but is this going ot be something that's planned to have for tauri at all, or not? suppose i'm streaming video through this RPC protocol, it would be incredibly wasteful to have to do a serialization+deserialization on both sides, for the data just to end up in a buffer again. if this is never planned to be supported i may consider doing a wasm thing that is running in the same address space instead
Well, the ipc in v2 will likely use custom protocols (like https://docs.rs/tauri/latest/tauri/struct.Builder.html#method.register_uri_scheme_protocol and the built-in tauri:// and asset:// protocols) to be able to send arbitrary binary payloads without the json (string) requirement.
That should speed it up a bunch but won't change anything about the message passing approach.
At least the windows webview has the concept of "host objects" which i think comes close to this, but its api is absolutely horrible to use so i wouldn't bet on that right now.
Also the webviews will get shared array buffers soon (webview2 already got it recently) but that is also closer to the message passing approach.
if this is never planned to be supported i may consider doing a wasm thing that is running in the same address space instead
How would that work or look like? The browser process is completely isolated
nevermind about the last part, misunderstood what you were talking about
Or in other (shorter) words, your example about the video without serialization will be supported soon-ish (or already kinda is, via custom protocols). But yeah, that's pretty different from the partially exposed rust object from the initial question which probably won't make it idk