guide: Add examples for number slices

This commit is contained in:
Nick Fitzgerald
2018-08-14 17:42:47 -07:00
parent fea41b4a87
commit b1e3101fd4
5 changed files with 31 additions and 4 deletions

View File

@ -217,9 +217,18 @@ versa when receiving a JavaScript `TypedArray` as a boxed slice in Rust.
## `[u8]` `[i8]` `[u16]` `[i16]` `[u32]` `[i32]` `[u64]` `[i64]` `[f32]` `[f64]`
| `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option<T>` parameter | `Option<T>` return value | JavaScript representation |
| `T` parameter | `&T` parameter | `&mut T` parameter | `T` return value | `Option<&T>` parameter | `Option<T>` return value | JavaScript representation |
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
| No | Yes | Yes | No | Yes | No | A JavaScript `TypedArray` view of the Wasm memory for the boxed slice of the appropriate type (`Int32Array`, `Uint8Array`, etc) |
| No | Yes | Yes | No | No | No | A JavaScript `TypedArray` view of the Wasm memory for the boxed slice of the appropriate type (`Int32Array`, `Uint8Array`, etc) |
Note that this does ***not*** copy the whole slice of memory back and forth into
the JavaScript heap from the Wasm linear memory.
### Example Rust Usage
```rust
{{#include ../../../examples/guide-supported-types-examples/src/number_slices.rs}}
```
### Example JavaScript Usage
```js
{{#include ../../../examples/guide-supported-types-examples/number_slices.js}}
```