mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
guide: Add examples of boxed number slices
This commit is contained in:
@ -8,3 +8,4 @@ import * as js_value from './js_value.js';
|
||||
import * as boxed_js_value_slice from './boxed_js_value_slice.js';
|
||||
import * as pointers from './pointers.js';
|
||||
import * as numbers from './numbers.js';
|
||||
import * as boxed_number_slices from './boxed_number_slices.js';
|
||||
|
@ -0,0 +1,22 @@
|
||||
import {
|
||||
take_boxed_number_slice_by_value,
|
||||
return_boxed_number_slice,
|
||||
take_option_boxed_number_slice,
|
||||
return_option_boxed_number_slice,
|
||||
} from './guide_supported_types_examples';
|
||||
|
||||
take_boxed_number_slice_by_value(new Uint8Array(100));
|
||||
|
||||
let x = return_boxed_number_slice();
|
||||
console.log(x instanceof Uint32Array); // true
|
||||
|
||||
take_option_boxed_number_slice(null);
|
||||
take_option_boxed_number_slice(undefined);
|
||||
take_option_boxed_number_slice(new Int16Array(256));
|
||||
|
||||
let y = return_option_boxed_number_slice();
|
||||
if (y == null) {
|
||||
// ...
|
||||
} else {
|
||||
console.log(x instanceof Int32Array); // true
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn take_boxed_number_slice_by_value(x: Box<[f64]>) {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn return_boxed_number_slice() -> Box<[u32]> {
|
||||
(0..42).collect::<Vec<u32>>().into_boxed_slice()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn take_option_boxed_number_slice(x: Option<Box<[u8]>>) {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn return_option_boxed_number_slice() -> Option<Box<[i32]>> {
|
||||
None
|
||||
}
|
@ -13,3 +13,4 @@ pub mod js_value;
|
||||
pub mod boxed_js_value_slice;
|
||||
pub mod pointers;
|
||||
pub mod numbers;
|
||||
pub mod boxed_number_slices;
|
||||
|
Reference in New Issue
Block a user