Replies: 3 comments
-
What about exporting a Rust My use case would be to export 2 different structs/classes, that share a common interface (trait from Rust perspective), and I would like to treat them the same on the TS side in most of the situations, but still have knowledge about their specific type... Not sure if that could be easily implemented, but I guess in the worst case by passing parameters like in the following example could make it not too difficult? #[wasm_bindgen]
trait Vehicle {
fn speed(&self) -> f64;
}
#[wasm_bindgen(implements_trait = "Vehicle")]
struct Car {
max_speed: f64,
}
impl Vehicle for Car {
fn speed(&self) -> f64 {
self.max_speed
}
}
#[wasm_bindgen(implements_trait = "Vehicle")]
struct Bicycle {
max_speed: f64,
}
impl Vehicle for Bicycle {
fn speed(&self) -> f64 {
self.max_speed
}
} Or is there already a workaround to achieve this today, by customizing the wasm_bindgen code generation? This issue looks like a proposal in a similar direction: |
Beta Was this translation helpful? Give feedback.
-
That's why we use Symbol for the interface names, because a Rust trait method can have the same name as a struct's method :3 |
Beta Was this translation helpful? Give feedback.
-
https://github.com/madonoharu/tsify generates |
Beta Was this translation helpful? Give feedback.
-
Hey everybody, does anybody know if we can generate Typescript
interface
usingwasm-bindgen
?For example, let's say I have this Rust code:
It will currently generate this Typescript code:
I'm wondering if we could generate a
interface
instead ofclass
:While
class
andinterface
are similar in Typescript, they have different meaning and it might be ideal to use one instead of the other.Beta Was this translation helpful? Give feedback.
All reactions