wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

Array not evaluated when pass to function.

Open bhoudebert opened this issue 1 year ago • 1 comments

 
#[wasm_bindgen] // blabla getter, constructor also on an impl
 struct TopStruct {
   attr1: SomeStructWithALotOfOptions,
   attr2: Array // in fact it is an array of ShameStruct -> would be a vector in Rust.
 }

#[wasm_bindgen]
 pub fn do_stuff(content: TopStruct) -> String {
  ...
 // somewhere iterating over attr2 to convert elements
 attr2Element.into_serde::<ShameStruct>() // ...
 } 

Regarding the quote code, I face some issue about the Array part. The thing is, everything works like a charm for att1 but for the Array this is wrong.

What I am getting for attr2Element is not a JsValue of what I send to the function but literally a pointer JsValue(Object({"ptr":1114248})) therefore serde cannot do his job.

I do not have any issue with an array of String, only an array of Struct.

Can't figure if there is a solution to that, I may have been too far with all these Struct and need to go back to simple plain JsValue but it would be a shame to drop type safe over there.

NB: label is bug but not sure it is.

Thanks.

bhoudebert avatar Aug 03 '22 20:08 bhoudebert

Okay I found some way around using the reflect api.

Reflect::get(&attr2element, &JsValue::from_str("att_of_attr2"));

Still very cumbersome to me.

bhoudebert avatar Aug 03 '22 21:08 bhoudebert