rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript

Home Page:https://rustwasm.github.io/docs/wasm-bindgen/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could I send an option with Element to js function?

GISerliang opened this issue · comments

Summary

I had a js library and the constructor need seed an option with container, width and height. The container must be an HTMLElement. So I want to create a struct and send it as JsValue to js libbrary use Rust and wasm_bindgen. But I got an error the trait `JsCast` is not implemented for `Options` .

Additional Details

The struct like this:

struct Options {
    pub container: web_sys::Element,
    pub width: u32,
    pub height: u32,
}

This isn't currently supported natively, see #2645. You should be able to do this with serde-wasm-bindgen, though: see the 'Preserving JavaScript values' section of their docs for how to get the web_sys::Element working.

This isn't currently supported natively, see #2645. You should be able to do this with serde-wasm-bindgen, though: see the 'Preserving JavaScript values' section of their docs for how to get the web_sys::Element working.

Thanks. I will try it.