-
Notifications
You must be signed in to change notification settings - Fork 25
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
Map JS Types to Rust #5
Comments
Here is the complete mappings file: |
Looks like @killercup beat me to it, hehe |
Ohh, so if I understand things correctly (which is errr, not necessarily the case), then most of the trouble will be to map Strings (utf16) to utf8-array buffers. This is mostly what I've understood from the post above. Complex JS typesThings like Objects, and the other higher-order JS things might need to be mapped down to strings before they can be passed (or, like json). There's been talk of using protobufs, but it seems most people are rather "meh" about it. Mapping stringsMapping Browservar encode = (new TextEncoder('utf-8')).encode
console.log(encode('hello world')
// => [Uint8Array]
var decode = (new TextDecoder('utf-8')).decode
console.log(decode(SomeUint8Array)
// =>'hello world' Nodevar TextEncoder = require('util').TextEncoder
var TextDecoder = require('util').TextDecoder
var encode = (new TextEncoder('utf-8')).encode
console.log(encode('hello world')
// => [Uint8Array]
var decode = (new TextDecoder('utf-8')).decode
console.log(decode(SomeUint8Array)
// =>'hello world' RustThis should also be possible from within Rust, as the code is rather fast (and small) thanks to optimizations. There's a possibility of creating custom attributes such as Shared memoryNow in an ideal scenario, we could use |
Currently we only support passing
i32
integers — great for math, but having more options would be great! We should probably look into rust-experiments and add some of the things they're doing.Also s/o to @killercup for giving pointers to get in the right direction! 🙏
See Also
The text was updated successfully, but these errors were encountered: