Open yoshuawuyts opened 6 years ago
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.
Things 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 utf16
to utf8
can either be done in Rust or in JS. I'm not sure about the Rust version, but the JS version seems to be:
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'
var 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'
This 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 #[expose_wasm]
to help streamline mappings in Rust, but it seems to rely on experimental Nightly features and nobody seems to have tried it yet.
Now in an ideal scenario, we could use SharedArrayBuffer
s to allocate memory in JS, and then pass it to Rust. I'm not sure if this is feasible, but it'd be neat if it were the case.
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