Generates TypeScript serialisation and deserialisation code from Rust structs and enums
strict mode enabledconst enum for Unit enums and respect discriminant values!TypedArray and copy byte blocks for Vec<{integer,float}> for greater performanceI'm pretty new to Rust and I've just hacked around until the tests pass 🤷♂️
There is much room for improvement and PRs are welcome!
Check the source for currently supported Rust types and their TypeScript equivalents.
You may also like to look at the Rust types used in the tests and the TypeScript generated from these.
Vec<T> are always converted to Uint8Array/Int8Array/etc whenever possible
and this might not always be desired.TextEncoder/TextDecoderbuild.rsThere is currently a single bool option to enable support for node.js
Buffer, so if you are running in the browser you probably don't want this enabled.
rust
bincode_typescript::from_file("./src/types.rs", "./ts/types.ts", false);
There is currently a single option (--buffer-support) to enable support for node.js
Buffer.
shell
./bincode-typescript --support-buffer ./src/types.rs > ./ts/types.ts
Before running the tests, ensure that you have all the node.js dependencies
installed by running yarn or npm i.
The tests check serialisation and deserialisation from generated TypeScript by round-tripping encoded data via stdio and asserting the expected values.
This builds on (ie. much TypeScript stolen from) the following projects.
The stated pros and cons are just personal opinion!
ts-rust-bridgetype + interface + moduleconst enum for Unit enumsserde-reflection/serde-generateserde so no messing around parsing Rustbuild.rsconst enum)