-
Notifications
You must be signed in to change notification settings - Fork 48
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
Move JS objects to Rust JSValues without deserialization #21
Comments
This is actually how it works internally. I considered making this publicly accessible but decided against it because I wanted a simple API without footguns and complexity. What's your use case for this? |
My use case is vectordotdev/vector#721, where I want to move objects containing {
timestamp: new Date(),
host: 'hostname',
message: 'some text'
} between Rust and JavaScript code. The structure of the objects is not fixed and it is not known in advance how many fields would be there and which ones of them would be dates. Right now it is implemented with serialization of the entire object to JSON. Because it is not known in advance which fields contain dates and which don't, in order to keep on-to-one correspondence between JavaScript and Rust dates I replace each However, this approach affects performance and I want to pass the objects without serialization in order to reduce the overhead of moving data between Rust and JavaScript. Ideally I would like to be able to construct |
I see, this is an interesting problem.
We can also consider making the lower level |
I've tried it, it works great.
I like this idea, it should improve the performance.
I think introducing |
I'd like to second this as a feature, because I'd like to be able to pass an object that contains a function back into JS. My use-case is for a game scripting engine. I know I could store a reference in a global object and use indexing or similar techniques, but that seems like a hacky workaround instead of a good solution. |
I'm wondering is it possible to store JavaScript objects as Rust values without deserialization, so that objects with richer structure can be passed back to
call_function
. For example, this codeoutputs now
result: String("[object Object]")
, but I would like it to outputresult: String("Mon Aug 12 2019 15:55:15 GMT+0000")
.The text was updated successfully, but these errors were encountered: