Rust 将JavaScript中的标记联合与wasm bindgen一起使用

Rust 将JavaScript中的标记联合与wasm bindgen一起使用,rust,wasm-bindgen,Rust,Wasm Bindgen,我有一个JavaScript对象类型,kind字段确定存在哪些其他字段。示例: {kind:0,name:“foo”} {种类:1,名称:“foo”,值:69} {种类:2} 我把它放在一个extern块中,用于生锈: #[wasm#u bindgen] 外部“C”{ Foo型; } 我需要访问此函数中的Foo值字段: #[wasm#u bindgen] fn使用_foo(foo:foo){ // ... } 如何以类型安全的方式执行此操作

我有一个JavaScript对象类型,
kind
字段确定存在哪些其他字段。示例:

{kind:0,name:“foo”}
{种类:1,名称:“foo”,值:69}
{种类:2}
我把它放在一个
extern
块中,用于生锈:

#[wasm#u bindgen]
外部“C”{
Foo型;
}
我需要访问此函数中的
Foo
值字段:

#[wasm#u bindgen]
fn使用_foo(foo:foo){
// ...
}
如何以类型安全的方式执行此操作