Currently there's no way to convert TypedArrays to Vec<T>s in rust, e.g., js_sys::Uint8Array to Vec<u8>, even though one can pass (via an implicit copy) a Uint8Array across the wasm boundary to rust functions expecting Vec<u8> or &[u8]. See this comment for motivation.
One thing I've been pondering recently is if it's possible to, in a generic fashion, convert anything that implements IntoWasmAbi into a JsValue. This would fit the bill perfectly for this issue as well as solve a number of other issues I've wanted to handle in the past. We currently do this ad-hoc in two locations:
It'd be great to somehow unify the two of these and provide this for all types (like &[u8] which can be converted into a JsValue). I'll noodle on this a bit...
I believe I've implemented this in https://github.com/rustwasm/wasm-bindgen/pull/918
Ok I've made another attempt to solve this in https://github.com/rustwasm/wasm-bindgen/pull/1147!
would it make sense to implement a to_vec() on top of copy_to()?
i.e. to allocate a new local Vec, copy_to() it, and return that?
Most helpful comment
I believe I've implemented this in https://github.com/rustwasm/wasm-bindgen/pull/918