-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support for u8 slices #5
Comments
Ah yes, definitely! Just to confirm (as I'm not so sure myself), what types would work on the JS side of things? Or rather, what type would this expect from JS? |
If I had to choose one: Uint8Array as "array of 8-bit unsigned integers" certainly is a close to fit for |
Besides |
Er sorry meant to respond, but @nickbabcock sounds good to me! @TimHambourger also I'd totally be down with that as well, sounds like a great idea! I think we could pretty easily add bindings for both |
I very interesting in use this great project, but lack of array binding forcing me to use stdweb. It will be great have borrowed or/and owned arrays. |
The README for this issue says "Vectors and slices of supported integer types", however, the change in git history (3c58aa7) extensively mentions floating point types. |
@clanehin ah yes indeed, all of the primitive typed array views are supported, including floats! |
Likely I'm missing something obvious, but while this works great across the js boundary, I can't seem to find the right traits to get this to work within Rust itself for these some_fetch_request.and_then(|resp_value| {
assert!(resp_value.is_instance_of::<Response>());
let resp: Response = resp_value.dyn_into().unwrap();
JsFuture::from(resp.array_buffer().unwrap())
}).map(|arrbuff_value| {
assert!(arrbuff_value.is_instance_of::<ArrayBuffer>());
// let arrbuff: ArrayBuffer = arrbuff_value.dyn_into().unwrap();
let typebuff: js_sys::Uint8Array = js_sys::Uint8Array::new(&arrbuff_value);
// Great so far...
// Now imagine we have some function `foo(&[u8])` or `foo<T: std::io::Read>(T)`, none of the normal tricks work:
foo(&typebuff);
foo((&typebuff).into());
foo(&typebuff[..]);
foo(typebuff.as_ref());
// etc, etc.
}); |
@aschampion ah currently that's not supported unfortunately! Want to open a separate issue for that though? (converting |
This commit implements the first half of [RFC rustwasm#5] where the `Deref` trait is implemented for all imported types. The target of `Deref` is either the first entry of the list of `extends` attribute or `JsValue`. All examples using `.as_ref()` with various `web-sys` types have been updated to the more ergonomic deref casts now. Additionally the `web-sys` generation of the `extends` array has been fixed slightly to explicitly list implementatoins in the hierarchy order to ensure the correct target for `Deref` is chosen. [RFC rustwasm#5]: https://github.com/rustwasm/rfcs/blob/master/text/005-structural-and-deref.md
This commit removes shims, where possible, for `structural` items. Instead of generating code that looks like: const target = function() { this.foo(); }; exports.__wbg_thing = function(a) { target.call(getObject(a)); }; we now instead generate: exports.__wbg_thing = function(a) { getObject(a).foo(); }; Note that this only applies to `structural` bindings, all default bindings (as of this commit) are still using imported targets to ensure that their binding can't change after instantiation. This change was [detailed in RFC rustwasm#5][link] as an important optimization for `structural` bindings to ensure they've got performance parity with today's non-`structural` default bindings. [link]: https://rustwasm.github.io/rfcs/005-structural-and-deref.html#why-is-it-ok-to-make-structural-the-default
Is there an update to the issue mentioned by @aschampion (getting |
You may find this useful: |
Returns
I'm hoping that you'd be open to more borrowed types (specifically
&[u8]
) in addition to BorrowedStr. This could be part of a larger issue to support Vec and other slices, but I figure&[u8]
might be easiest and would be implemented very closely to BorrowedStr.Use case:
After I use a FileReader to read a binary file into an ArrayBuffer and create WebAssembly.Memory (I believe that flow is correct), I want to send the data to rust for parsing.
The text was updated successfully, but these errors were encountered: