You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[wasm_bindgen] can only be applied to a function, struct, enum, impl, or extern block
I'd love to here move about traits and wasm-bindgen. I've looked through several issues such as rustwasm/rfcs#11 but seem to be missing some likely longer discussion.
the trait bound impl Quacks: wasm_bindgen::convert::traits::FromWasmAbi is not satisfied
Thanks for the report here! I agree this would be pretty slick to support, but unfortunately I'm not sure how it would be possible to support. I think the best thing to do in lieu of it though is to use the duck-typed interface pattern, and does that work for your use case?
Unfortunately traits going back and forth aren't supported in wasm right now, and there's not a great way of passing in either a RUst argument or a JS argument to something like make_em_quack_to_this. For that you'd have to use a Rust-internal API which is trait bound, and use that from Rust instead.
Motivation
To be able to use traits witn wasm-bindgen as an alternative to "Duck-Type Interface"s.
Currently, this produces two errors:
#[wasm_bindgen] can only be applied to a function, struct, enum, impl, or extern block
I'd love to here move about traits and wasm-bindgen. I've looked through several issues such as rustwasm/rfcs#11 but seem to be missing some likely longer discussion.
the trait bound impl Quacks: wasm_bindgen::convert::traits::FromWasmAbi is not satisfied
Reading through https://docs.rs/wasm-bindgen/0.2.50/wasm_bindgen/convert/index.html it seems to as though implementing your own conversions is discouraged. It might be necessary to support traits like this but I am not sure.
I should note, is it possible to implement the various conversion traits for the example above? I'm wondering if it has been tried.
Proposed Solution
Enable the following example.
The trait would generate a TypeScript interface called
Quacks
as well as a JavaScript object. This will likely need to leverageClosure
.Alternatives
Use the recommended "Duck-Typed Interface".
Additional Context
"Duck-Typed Interfaces" are defined in the docs as such:
The text was updated successfully, but these errors were encountered: