-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to send a Rust type to JS #286
Comments
You could use |
Hm, can |
You have 52 bits of precision on f64, so unless your hardware has more than 4.5 petabytes of RAM you should be fine. Alternatively you can make it a pair of two 32bit integers. Also, instead of hashmap you could just store your stuff on |
https://github.com/GabrielCastro/neon-serde may be of interest to you |
@softprops I already do use neon-sreder, however I am interested in round-tripping a Rust struct as is, without serialization, which is not applicable in my particular case. |
@matklad Would you be up for writing this up as an RFC? I think it would help understand the motivation and design better. |
I am unlikely to write an RFC, but this thing from NAPi is exactly what I need: |
@matklad well that is cool but how do you use it from rust? napi crate seems to be year old and without any further updates is there a simple way to call |
Hey, |
@joshbenaron This isn't a great issue to comment on since it's about sending references to Rust data structures and not serialization. You may be interested in this proposal: #701 With that said, I've done a decent amount of benchmarking and because of the high cost of going between Node/V8 and native code (FFI), JSON serialization almost* always outperforms transcoding directly between Rust and JS. *The one exception is if the structures contain binary data in the form of |
Is this issue supposed to be closed? I'm not really seeing a solution to this problem in the previous replies; only a couple workarounds that seem to have tradeoffs around memory leaks and isolation in particular. |
Ah, yes, JsBox looks like it solves the issue - but I hadn't run across it yet, since it didn't seem to be mentioned in any of the replies here :) Thanks! |
Hi! I'd love to be able to create some value of type
Foo
in Rust, return it to JavaScript as an opaque object, and then get back a reference to it. I imagine API likeLooks like currently the only way to move a Rust value to JavaScript is to wrap it into a JsClass, but it's often not convenient. For example, JsClass always has an init method, but often it does not makes sense (or outright impossible) to give JavaScript an ability to create an instance of the type.
I am not sure that the my description of the problem makes sense, so there's a TL;DR version. I want to
T
in Rust.&T
from it.The text was updated successfully, but these errors were encountered: