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

Typed Array discoverability #909

Merged
merged 31 commits into from
Sep 14, 2022
Merged

Typed Array discoverability #909

merged 31 commits into from
Sep 14, 2022

Conversation

dherman
Copy link
Collaborator

@dherman dherman commented Jun 17, 2022

This PR adds API docs for typed arrays, as well as several conveniences in the API:

  • JsTypedArray::new() and JsTypedArray::from_buffer for constructing typed array objects
  • Type aliases for typed array types (e.g. JsUint32Array)

Collectively, these changes should make the Neon typed arrays API more discoverable and easier to get started using.

RFC: neon-bindings/rfcs#47

@dherman dherman marked this pull request as ready for review July 1, 2022 00:45
@dherman dherman changed the title [draft] Typed Array discoverability Typed Array discoverability Jul 1, 2022
crates/neon/src/types_impl/buffer/types.rs Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Outdated Show resolved Hide resolved
@dherman dherman force-pushed the typed-array-discoverability branch from 0a79f32 to 7ac46cb Compare July 8, 2022 17:57
test/napi/src/js/objects.rs Outdated Show resolved Hide resolved
test/napi/src/js/objects.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Outdated Show resolved Hide resolved
@dherman dherman force-pushed the typed-array-discoverability branch from 1601966 to bdf4a41 Compare July 12, 2022 07:12
…:types API docs

- Delete the PowerPoint-generated digram
- Refactor the module tree slightly, in order to wrap the module docs with `#[aquamarine]` attribute
- Flesh out the remaining blank spots in the typed array API docs
- Change the `Binary` trait to use an associated constant instead of a nullary method
- change from top-to-bottom to left-to-right
- make rectangles rounded
…opy around them

- Turn every node in the diagrams into a link to the relevant type's API docs
… convenient `from_buffer()`

- Add `TypedArray::byte_length()`
- Add `JsTypedArray::{byte_offset, buffer}`
- Revert visibility of Binary back to public to enable typed array abstractions
- Add tests for buffer aliasing and argument validation
- Add tests for `byte_length`, `byte_offset`, and `buffer` methods
…l the metadata, avoiding extra FFI calls to

retrieve that data.
@dherman dherman force-pushed the typed-array-discoverability branch from 26a4d59 to 3f0fc4c Compare July 22, 2022 21:00
- byte_offset -> offset
- byte_length -> size
- to_region -> region
- to_typed_array and region take &self
- JsArrayBuffer::region static method, for doc discoverability
- add tests about region validation
@dherman dherman requested a review from kjvalencik August 1, 2022 20:58
crates/neon/Cargo.toml Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/mod.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/mod.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/mod.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/mod.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Outdated Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Show resolved Hide resolved
crates/neon/src/types_impl/buffer/types.rs Show resolved Hide resolved
test/napi/lib/typedarrays.js Outdated Show resolved Hide resolved
- make doc-related crates (doc-comment, aquamarine) optional
- `Binary` only requires `Clone`, not `Copy` or `Debug`
- `Region` API changes
  * still impls Copy but all its methods take a reference
  * range checks throw `RangeError` instead of panicking
- minor code improvements
  * copy-editing nit in doc comment
  * `buffer/types.rs` imports from `types_impl` not `types` so it's clear why it has private access
  * use `map_err` to clean up some code
  * simplify `detach` test helper function
@dherman dherman merged commit 37a9b93 into main Sep 14, 2022
@dherman dherman deleted the typed-array-discoverability branch September 14, 2022 17:37
@dherman dherman mentioned this pull request Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants