Closed
Description
Motivation
I'm trying to use an existing JS library (from NPM). One of the methods in this library's API expects to get passed an ArrayBuffer
object. Therefore, I need to be able to generate an ArrayBuffer
from the Rust code.
It is already possible to do so by doing:
let arr = unsafe { Uint8Array::view(my_buf) };
let arr_clone = Uint8Array::new(arr).buffer();
However that requires using unsafe code.
Proposed Solution
Add an ArrayBuffer::from_data(&[u8])
function in order to move the safety issues within wasm-bindgen.
Similarly, we can also add similar from_data
methods to the Uint8Array
types and similar.