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
Because the JS classes generated for exported Rust structs do not currently specify a parent class, they are implicit subclasses of Object—that is, their prototype objects are Object.prototype. However, there are many situations where the parent class (prototype object) of one's exported structs should be something other than this default.
Proposed Solution
I propose a new super = Type attribute for the wasm_bindgen macro, as follows:
#[wasm_bindgen]pubstructParent{ ... }#[wasm_bindgen(super=Parent)]pubstructChild{ ... }// the superclass might be imported from JS#[wasm_bindgen]extern"C"{#[wasm_bindgen(extends=Grandparent)]pubtypeImportedParent;}#[wasm_bindgen(super=ImportedParent)]pubstructChildOfImportedParent{ ... }// or might be a built-in published by the `js_sys` crate#[wasm_bindgen(super=js_sys::Date)]pubstructCustomDate{ ... }// or might be a Web IDL published by the `web_sys` crate#[wasm_bindgen(super=web_sys::XmlHttpRequest)]pubstructMyAjaxRequest{ ... }
In each case, the generated JavaScript class would include the relevant extends clause, and Rust implementations for the DeRef, AsRef, AsMut and From traits would all be automatically generated.
The text was updated successfully, but these errors were encountered:
AFAIK no one really knows how best to progress on this at this point in terms of what the design for this would look like, but proposals for such a design (fleshed out as an RFC most likely) would be most welcome!
Motivation
Because the JS classes generated for exported Rust structs do not currently specify a parent class, they are implicit subclasses of
Object
—that is, their prototype objects areObject.prototype
. However, there are many situations where the parent class (prototype object) of one's exported structs should be something other than this default.Proposed Solution
I propose a new
super = Type
attribute for thewasm_bindgen
macro, as follows:In each case, the generated JavaScript class would include the relevant
extends
clause, and Rust implementations for theDeRef
,AsRef
,AsMut
andFrom
traits would all be automatically generated.The text was updated successfully, but these errors were encountered: