into_jsvalue - Rust Macro for Deriving From for JsValue
This crate provides a derive macro IntoJsValue for Rust that simplifies the implementation of From<T> for wasm_bindgen::JsValue.
This crate is for a particular use case.
wasm_bindgen only supports c-style enums.
tsify allows us to get around this using serde-wasm-bindgen, but it only works for synchronous functions
This crate adds a simple derive macro that will implement the neccassary From implementation
use ;
use *;
use IntoJsValue;
use Tsify;
pub async
pub async
// This does not work because wasm_bindgen only supports c-style enums
// this allows test() to work, but not async test. It does not impl the required trait
Usage
- Add this crate as a dependency in your Cargo.toml:
[]
= "0.1.0" # Replace with the actual version
# include serde, wasm-bindgen and serde-wasm-bindgen
- Use the
#[derive(IntoJsValue)]attribute on your struct definition: Note:: the struct must impl serde::Serialize
The macro will generate the following code.
// generated by the macro
Important Note:
This crate requires serde, wasm_bindgen, and serde_wasm_bindgen crates to be present in your project.
License
This project is licensed under the MIT License - see the LICENSE file for details.