-
-
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 converting js_sys typed arrays to Vec #811
Comments
One thing I've been pondering recently is if it's possible to, in a generic fashion, convert anything that implements It'd be great to somehow unify the two of these and provide this for all types (like |
This commit implements a generic function on `JsValue` which can convert *any* Rust value that implements `IntoWasmAbi` into the corresponding `JsValue`. This can be handy when binding APIs and the intermediate JS value is needed is needed over a few function calls or is otherwise needed when calling APIs that take `JsValue` but otherwise work with Rust primitives. One of the primary intended use cases for this will be interoperation with the various `JsValue`-taking functions (or `Object`) in `web-sys`. cc rustwasm#811
I believe I've implemented this in #918 |
For all typed arrays, this commit adds: * `TypedArray::view(src: &[Type])` * `TypedArray::copy_to(&self, dst: &mut [Type])` The `view` function is unsafe because it doesn't provide any guarantees about lifetimes or mutability. The `copy_to` function is, however, safe. Closes rustwasm#811
Ok I've made another attempt to solve this in #1147! |
Currently there's no way to convert
TypedArray
s toVec<T>
s in rust, e.g.,js_sys::Uint8Array
toVec<u8>
, even though one can pass (via an implicit copy) aUint8Array
across the wasm boundary to rust functions expectingVec<u8>
or&[u8]
. See this comment for motivation.The text was updated successfully, but these errors were encountered: