'How to return nested array from wasm_bindgen function

I have a rust program which I would like to run as web assembly in javascript. I have a function which I want to return a 3D array, so I can plot some data on a graph on the frontend, but I cannot find a way to return such data. Having a look at js_sys there is no general Array type, only specific types for 2D arrays such as Uint32Array.

I would like the function signature to look something like this:

#[wasm_bindgen]
pub fn sk_dataset(input: &str) -> Vec<Vec<i32>>;

I have tried return a struct with the wasm_bindgen decorator like this:

#[wasm_bindgen]
pub struct DataSet {

    pub data: Vec<Vec<i32>>
}

But I get an error stating that

the trait bound `Vec<i32>: JsObject` is not satisfied
required because of the requirements on the impl of `IntoWasmAbi` for `Box<[Vec<i32>]>`

The tutorial over at https://rustwasm.github.io/docs/wasm-bindgen/reference/types/exported-rust-types.html only has examples of structs exported with basic types like i32s, how can I export a struct with more complex members?



Solution 1:[1]

My guess: You are encoding your URLs in your HTML incorrectly. Keep in mind in HTML & must be encoded as &amp;, if the & is followed by a valid entity. As a general rule you should just do it always.

See Do I encode ampersands in <a href...>?

Example:

WRONG:

<form action="/getUserConnectionsList?login=**********&pagelimit=25&page=1&ot=asc&of=openDatetime&section=userActivity">
</form>

RIGHT:

<form action="/getUserConnectionsList?login=**********&amp;pagelimit=25&amp;page=1&amp;ot=asc&amp;of=openDatetime&amp;section=userActivity">
</form>

Considering you are using Spring, you are probably using Thymeleaf. If you use th:action and an @{...} expression, it will do the encoding for you:

<form th:action="@{'/getUserConnectionsList'(login='**********', pagelimit=25, page=1, ot=asc, of=openDatetime, section=userActivity")}">
</form>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RoToRa