#Working with vectors

1 messages · Page 1 of 1 (latest)

leaden yoke
#

My rust function in the backend retuns a vector that contains custom data (data: Vec<Data> for example). How do I work with this vector in the frontend using js?

shrewd isle
#

Provided that Serde can serialize the Data type, it will appear as an array in JS. The following examples are identical declarations.
Rust:

struct Data {
  field_one: String,
  field_two: bool,
}
let data = Data {
  field_one: String::from("Hello, World!"),
  field_two: true,
};

JS:

let data = {
  fieldOne: "Hello, World!",
  fieldTwo: true,
};
#

So as an array in JS, that can be accessed with:

let data = await invoke("feed_data");
let dataStart = data[0].fieldOne;