JsValue into Rust wasm_bindgen type

Suppose we have:

#[wasm_bindgen]
extern "C" {
    type Bar;
}
pub fn (x: JsValue) {
  let r: JsValue = js_sys::Reflect::get(x, &"foo".into()).unwrap();
}

Now, I know that r is an object of type Bar (as defined above). How do I convert this r into a Bar ?

Use JsCast::unchecked_into().

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.