-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Use Symbol for trait impls #2073
Comments
Currently there isn't support for traits mostly because no one's worked on it yet, not necesesarily because of symbol collisions. Implementing this seems fine to me though, and I'd be curious to see what it would look like! |
I have a lot of interwined enums, and enums cant have methods for wasm_bindgen, so this for simplifying a lot of utils would be awesome |
Tl;dr: Looking for a mentor for a first open source contribution for this issue I am new to wasm and have been learning about I would like to work on this issue, however, I am new to the level of engineering (virtual machine, assembly code) that this effort would likely entail. I have more experience as an implementor of existing Rust libraries and this would be my first Rust open source contribution. Would anyone in the be interested in mentoring/pairing on this effort with me? Thanks! |
Technically speaking, methods are just function that get called in a weird way (there are no methods in Haskell, only functions, even for "traits"). But it was wasm_bindgen decision to convert Rust impl/trait functions in Rust to methods in JavaScript. |
It's been 4 years since this issue. Would be great to be able to use wasm_bindgen with impl+trait. I assume this isn't being worked on anywhere? |
This might also be related to this discussion: #3254 |
Motivation
Currently,
#[wasm_bindgen]
cannot be applied to trait impls, I guess this is to avoid method name collision? If that is the case, then JavaScript Symbol is a perfect solution for this.Proposed Solution
Convert trait methods to JavaScript methods with symbols for names, and trait names can be converted to a namespace object of symbols. For example:
This code:
can be converted to this TypeScript declaration:
Note
In the JavaScript glue code,
Read
object must always be created beforeclass Foo
.Alternatives
Additional Context
The text was updated successfully, but these errors were encountered: