Crates.io | bincode-typescript |
lib.rs | bincode-typescript |
version | 0.1.0 |
source | src |
created_at | 2020-10-23 13:27:40.061977 |
updated_at | 2020-10-23 13:27:40.061977 |
description | Generates TypeScript serialisation and deserialisation code from Rust structs and enums |
homepage | |
repository | https://github.com/timfish/bincode-typescript |
max_upload_size | |
id | 304669 |
size | 78,524 |
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/TextDecoder
build.rs
There 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.
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
.
./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-bridge
type
+ interface
+ module
const enum
for Unit enumsserde-reflection/serde-generate
serde
so no messing around parsing Rustbuild.rs
const enum
)