mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
guide: Add examples for number slices
This commit is contained in:
parent
fea41b4a87
commit
b1e3101fd4
@ -9,3 +9,4 @@ import * as boxed_js_value_slice from './boxed_js_value_slice.js';
|
|||||||
import * as pointers from './pointers.js';
|
import * as pointers from './pointers.js';
|
||||||
import * as numbers from './numbers.js';
|
import * as numbers from './numbers.js';
|
||||||
import * as boxed_number_slices from './boxed_number_slices.js';
|
import * as boxed_number_slices from './boxed_number_slices.js';
|
||||||
|
import * as number_slices from './number_slices.js';
|
||||||
|
9
examples/guide-supported-types-examples/number_slices.js
Normal file
9
examples/guide-supported-types-examples/number_slices.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import {
|
||||||
|
take_number_slice_by_value,
|
||||||
|
return_number_slice,
|
||||||
|
take_option_number_slice,
|
||||||
|
return_option_number_slice,
|
||||||
|
} from './guide_supported_types_examples';
|
||||||
|
|
||||||
|
take_number_slice_by_shared_ref(new Float64Array(100));
|
||||||
|
take_number_slice_by_exclusive_ref(new Uint8Array(100));
|
@ -14,3 +14,4 @@ pub mod boxed_js_value_slice;
|
|||||||
pub mod pointers;
|
pub mod pointers;
|
||||||
pub mod numbers;
|
pub mod numbers;
|
||||||
pub mod boxed_number_slices;
|
pub mod boxed_number_slices;
|
||||||
|
pub mod number_slices;
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn take_number_slice_by_shared_ref(x: &[f64]) {}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn take_number_slice_by_exclusive_ref(x: &mut [u8]) {}
|
@ -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]`
|
## `[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
|
### Example Rust Usage
|
||||||
the JavaScript heap from the Wasm linear memory.
|
|
||||||
|
```rust
|
||||||
|
{{#include ../../../examples/guide-supported-types-examples/src/number_slices.rs}}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example JavaScript Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
{{#include ../../../examples/guide-supported-types-examples/number_slices.js}}
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user