| 1 |
use wasm_bindgen::prelude::*; |
| 2 |
use wasm_bindgen_test::*; |
| 3 |
|
| 4 |
#[wasm_bindgen(module = "tests/wasm/struct_vecs.js")] |
| 5 |
extern "C" { |
| 6 |
fn pass_struct_vec(); |
| 7 |
fn pass_invalid_struct_vec(); |
| 8 |
} |
| 9 |
|
| 10 |
#[wasm_bindgen] |
| 11 |
pub struct ArrayElement; |
| 12 |
|
| 13 |
#[wasm_bindgen] |
| 14 |
impl ArrayElement { |
| 15 |
#[wasm_bindgen(constructor)] |
| 16 |
pub fn new() -> ArrayElement { |
| 17 |
ArrayElement |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
#[wasm_bindgen] |
| 22 |
pub fn consume_struct_vec(mut vec: Vec<ArrayElement>) -> Vec<ArrayElement> { |
| 23 |
vec.push(ArrayElement); |
| 24 |
vec |
| 25 |
} |
| 26 |
|
| 27 |
#[wasm_bindgen] |
| 28 |
pub fn consume_optional_struct_vec(vec: Option<Vec<ArrayElement>>) -> Option<Vec<ArrayElement>> { |
| 29 |
vec.map(consume_struct_vec) |
| 30 |
} |
| 31 |
|
| 32 |
#[wasm_bindgen_test] |
| 33 |
fn test_valid() { |
| 34 |
pass_struct_vec(); |
| 35 |
} |
| 36 |
|
| 37 |
#[wasm_bindgen_test] |
| 38 |
fn test_invalid() { |
| 39 |
pass_invalid_struct_vec(); |
| 40 |
} |