Hey all,
Typeshare is a nice library for Rust created by 1Password. It allows people to export types defined in Rust to other languages.
I spent a few days creating support for ReScript and it’s now pending merging by the authors. Here’s the tracking issue. If you feel this would be a nice addition to the library, go give it a thumbs up to hopefully make authors notice it. Of course you can also use the fork meanwhile. It should handle the basic cases ok, but you can always ping me if you notice something weird.
So why is this something useful? Say you have a backend API implemented in Rust and want to make sure frontend written in ReScript is always guaranteed to be up to date with the API types. By automatically generating the ReScript types directly from Rust API types it’s possible to ensure this.
The reason I find this specific solution very practical is it allows following nice features:
- Override certain Rust types with custom ReScript module types. E.g
uuid::Uuid→MyCustomUuid.t - Decorators such as
@schemafor easy rescript-schema/sury support. - Handles fairly complex nested enum/struct types and converts them to ReScript variants and records. Or at least tries to, more testing is probably needed.
If you’re using both ReScript and Rust, and have no existing end-to-end typesafety solution, try this out and comment findings in the issue/PR or here.