(wasm-bindgen) Using tagged unions from JavaScript

I have a JavaScript object type where the kind field determines what other fields are present. Examples:

{ kind: 0, name: "foo" }
{ kind: 1, name: "foo", value: 69 }
{ kind: 2 }

I have a Rust function that takes this value from JavaScript and it needs to do pattern matching on this value. What's the best way to do this?

This is called an internally tagged enum. Serde has a page about it here.

1 Like

asked on stack overflow: rust - Using tagged unions from JavaScript with wasm-bindgen - Stack Overflow