A crate to make working with wasm-bindgen easier.

This crate contains the wasm_bindgen_struct macro which can be used to declare wasm_bindgen types, and implement getters/setter as if they were normal rust structs. It can also be used to implement methods for the type, including inline mapping to overcome wasm-bindgen-futures limitations.

Example

```rust // Or you can use this instead to avoid needing to import // the macro throughout your crate // #[macrouse] // extern crate wasmbindgenstruct; use wasmbindgenstruct::wasmbindgen_struct;

[wasmbindgenstruct]

// module here means this type comes from the JS "my-module" module // with the class name aAnotherType

[opts(module = "my-module", js_name = "AnotherType")]

struct MyJsType { // field names are automatically converted to camelCase fielda: String, // ...but can be manually specified if needed #[opts(jsname = "fieldb")] fieldb: String, }

[wasmbindgenstruct]

[opts(module = "my-module")]

impl MyJsType { // Automatically gets the static_method_of = MyJsType applied, // as well as catch due to the Result fn apple() -> Result;

// async functions in wasm-bindgen can only currently return // (), JsValue, or Result<_, JsValue>, whereis one of // the two previously mentioned types. We useMapValue // to tell the macro that the binding method should returnT, // but we'll map the value toU` async fn oranges(&self) -> MapValue { self .orangesjs() .await .unchecked_into::() .into() } } ```

The above expands to:

```rust

// For getters/setters

[wasm_bindgen(module = "my-module")]

extern "C" { #[wasmbindgen(jsname = "AnotherType")] type MyJsType;

#[wasmbindgen( method, getter, jsclass = "AnotherType", jsname = "fieldA" )] fn fielda(this: &MyJsType) -> String;

#[wasmbindgen( method, setter, jsclass = "AnotherType", jsname = "fieldA" )] fn setfield_a(this: &MyJsType, value: String);

#[wasmbindgen( method, getter, jsclass = "AnotherType", jsname = "fieldb" )] fn fieldb(this: &MyJsType) -> String; #[wasmbindgen( method, setter, jsclass = "AnotherType", jsname = "fieldb" )] fn setfield_b(this: &MyJsType, value: String); }

// And for methods impl MyJsType { fn apple() -> Result { #[wasmbindgen(module = "my-module")] extern "C" { #[wasmbindgen(staticmethodof = MyJsType, jsname = "apple")] #[wasmbindgen(catch)] fn applejs() -> Result; } Self::applejs() } async fn oranges(&self) -> String { #[wasmbindgen(module = "my-module")] extern "C" { #[wasmbindgen(method, jsname = "oranges")] async fn orangesjs(this: &MyJsType) -> JsValue; } self .orangesjs() .await .uncheckedinto::() .into() } } ```

#[opts(...)] on structs

#[opts(...)] on struct fields

#[opts(...)] on impl

#[opts(...)] on impl methods

Treatment of Special Types