Skip to content
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

DataView / ArrayBuffer ergonomics are not well discoverable #3170

Open
chrysn opened this issue Nov 28, 2022 · 0 comments · May be fixed by #3171
Open

DataView / ArrayBuffer ergonomics are not well discoverable #3170

chrysn opened this issue Nov 28, 2022 · 0 comments · May be fixed by #3171

Comments

@chrysn
Copy link
Contributor

chrysn commented Nov 28, 2022

Motivation

Working with Web Bluetooth, web-sys APIs give me js_sys::DataView objects. Conceptually, these are JavaScript's version of (typed) slices. Accessing them as slices is hard, though.

Proposed Solution

The documentation of DataView and Array should point users to the family of types around js_sys::Uint8Array, and how to turn one that was obtained into a such an array (my naïve let ble_response: js_sys::Uint8Array = characteristic.read_value().js2rs().await?.into(); did not do the trick).

Alternatives

Up until in-depth documentation review with some guessing jumps, I turned my data views into vectors going through my_vec.extend((0..ble_response.byte_length()).map(|i| ble_response.get_uint8(i))) on them. This feels extremely unergonomic and inefficient.

chrysn added a commit to chrysn-pull-requests/wasm-bindgen that referenced this issue Nov 28, 2022
chrysn added a commit to chrysn-pull-requests/wasm-bindgen that referenced this issue Nov 28, 2022
chrysn added a commit to chrysn-pull-requests/wasm-bindgen that referenced this issue Nov 28, 2022
@chrysn chrysn linked a pull request Nov 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant