wasm-bindgen
wasm-bindgen copied to clipboard
Add support for traits
Tries to fix #2073 I honestly don't know what I'm doing but I really want this and it sure will be a nice addition to the ecosystem.
- [x] Correctly implement information struct of traits on the AST
- [x] Extract information of trait with the proc-macro
- [ ] Generate typescript code for traits so you don't have a bad time developing
- [ ] Generate JS glue code correctly
- [ ] Make test unit
@alexcrichton sorry to bother but is there a way to generate JSDocs and ts signatures with the adapter types. I think I need to read a little more to understand how adapter type works
or maybe im going the wrong way
Kinda related btw microsoft/TypeScript#10570
@alexcrichton sorry to bother but is there a way to generate JSDocs and ts signatures with the adapter types. I think I need to read a little more to understand how adapter type works
or maybe im going the wrong way
yeah this seems more complicated than I thought, is there no way to generate ts documentation without having code on the wit module? It really seems like the only way which means I need to modify the library more than I would like for generating the interface method signatures documentation...
@alexcrichton sorry for still bothering you, but what are your thoughts on how I should follow on this?
Sorry this is a feature which off the top of my head I don't really know how it would work or how it would be integrated. I unfortunately don't have the time to help out right now with deisgn as well.
yeah understandable, this is currently a mess but it was quite interesting to do. I'm gonna finish the implementation and then clean some code and make all needed tests and see what needs fixing
this would honestly be awesome to have!!
Theres no way to guarantee API stability between TS/JS and rust right now because you cant have build time failure for JS type incompatibility. Its also really difficult to cover with tests because you cant force rust behaviour from TS/JS where the tests will be. Its very difficult to ensure that these codepaths get hit.
I cant believe this isn't a higher priority - how are teams working with this? Do they just deploy and wait for it to break?
@alexcrichton Any changes on this? I could really use the feature on our production system. Currently we have a huge, nasty workaround that I would love to get rid of.
this PR would solve the following issues:
- https://github.com/rustwasm/wasm-bindgen/issues/2714
- https://github.com/rustwasm/wasm-bindgen/issues/1591
- https://github.com/rustwasm/wasm-bindgen/issues/1197
Well my attempts to merge in 0.2.81 to this branch were unsuccessful, because I also don't know what I'm doing. Getting failures in the CLI on decode.
Quick question. Let's say I have a piece of code like the following:
#[wasm_bindgen]
pub struct A {}
#[wasm_bindgen]
impl A {
pub fn a(&self) {
// Do something
}
}
pub trait Trait {
fn b(&self);
}
impl Trait for A {
fn b(&self) {
// Do something else
}
}
As far as I understand, this will only export a class A and its method a() in JavaScript, but I'd also like to call A::b() – is there a way to do this as of today?
provide a wrapper method for calling it :P
@ImUrX ok, so that's the only solution for now. Thank you!
I would be happy to review the Rust and JS part, but the TS part needs a different maintainer that has the time to do the design work and eventually review it.
tbh the typescript part is easy, i just havent had the time and will to finish the PR, aside from the rust part of generating the typescript code being a lot of pain
Hi, I'm interested in this feature, would you be ok if I took a stab at it using your PR as a base? I hope I'll be able to fix the last couple things.
yeah, be free
Hey, I'm also interested in this feature. Do you, @vdagonneau and everyone else, wanna team up and work on this PR?