madonoharu / tsify

A library for generating TypeScript definitions from rust code.
Apache License 2.0
311 stars 42 forks source link

Tsify without wasm_bindgen #13

Open Alfred-Mountfield opened 1 year ago

Alfred-Mountfield commented 1 year ago

Hello, I was just wondering if it's possible to decouple this from wasm_bindgen.

I understand that the original purpose of the library was to focus on wasm_bindgen but I was wondering if this could become a more generalised library for creating cross-language type definitions, similar to https://github.com/1Password/typeshare

stefnotch commented 1 year ago

Judging from the readme, the intent seems to be that this library is used with wasm bindgen

https://github.com/madonoharu/tsify#crate-features

siefkenj commented 9 months ago

If you put a "web" feature in your crate, you can do

#[cfg(feature = "web")]
use tsify::Tsify;
#[cfg(feature = "web")]
use wasm_bindgen::prelude::*

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "web", derive(Tsify))]
pub struct MyStruct {
   ...
}

then compile with wasm-bindgen and copy out the types. Not exactly what you want, but you can maintain a non-wasm version of your crate.