{"id":13550175,"url":"https://github.com/timfish/bincode-typescript","last_synced_at":"2025-05-05T21:16:29.597Z","repository":{"id":57509045,"uuid":"306037407","full_name":"timfish/bincode-typescript","owner":"timfish","description":"Generates TypeScript bincode serialisation code from Rust structs and enums","archived":false,"fork":false,"pushed_at":"2021-03-12T00:06:21.000Z","size":50,"stargazers_count":21,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T02:50:03.317Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timfish.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-21T13:41:26.000Z","updated_at":"2025-04-26T22:02:17.000Z","dependencies_parsed_at":"2022-09-19T13:50:53.032Z","dependency_job_id":null,"html_url":"https://github.com/timfish/bincode-typescript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfish%2Fbincode-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfish%2Fbincode-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfish%2Fbincode-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfish%2Fbincode-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timfish","download_url":"https://codeload.github.com/timfish/bincode-typescript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252429947,"owners_count":21746571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:01:29.807Z","updated_at":"2025-05-05T21:16:29.578Z","avatar_url":"https://github.com/timfish.png","language":"Rust","readme":"# bincode-typescript\r\n\r\nGenerates TypeScript serialisation and deserialisation code from Rust structs\r\nand enums\r\n\r\n## Goals\r\n\r\n- Generate TypeScript code directly from Rust source\r\n- TypeScript must compile with [`strict` mode enabled](https://github.com/timfish/bincode-typescript/blob/master/tests/build.rs)\r\n- Avoid Object Orientated TypeScript for better tree-shaking and optimisation\r\n- TypeScript should be ergonomic and high performance\r\n  - Use `const enum` for Unit enums and respect discriminant values!\r\n  - Use `TypedArray` and copy byte blocks for `Vec\u003c{integer,float}\u003e` for greater performance\r\n\r\n## Status\r\n\r\nI'm pretty new to Rust and I've just hacked around until the tests pass 🤷‍♂️\r\n\r\nThere is much room for improvement and PRs are welcome!\r\n\r\nCheck the source for [currently supported Rust types and their TypeScript\r\nequivalents](https://github.com/timfish/bincode-typescript/blob/master/src/types.rs#L30).\r\n\r\nYou may also like to look at the [Rust\r\ntypes](https://github.com/timfish/bincode-typescript/blob/master/tests/test_types.rs)\r\nused in the tests and the [TypeScript\r\ngenerated](https://github.com/timfish/bincode-typescript/blob/master/tests/test_types.ts)\r\nfrom these.\r\n\r\n## Current Issues \u0026 Limitations\r\n\r\n- All values must be owned\r\n- Generic structs/enums will almost certainly cause a panic\r\n- All types must be in a single file\r\n- Serde attributes are not currently respected\r\n- `Vec\u003cT\u003e` are always converted to `Uint8Array/Int8Array/etc` whenever possible\r\n  and this might not always be desired.\r\n- Generated code will not work on node \u003c v11 due to the global usage of `TextEncoder/TextDecoder`\r\n\r\n## Example via `build.rs`\r\n\r\nThere is currently a single `bool` option to enable support for node.js\r\n`Buffer`, so if you are running in the browser you probably don't want this enabled.\r\n\r\n```rust\r\nbincode_typescript::from_file(\"./src/types.rs\", \"./ts/types.ts\", false);\r\n```\r\n\r\n## Example via CLI\r\n\r\nThere is currently a single option (`--buffer-support`) to enable support for node.js\r\n`Buffer`.\r\n\r\n```shell\r\n./bincode-typescript --support-buffer ./src/types.rs \u003e ./ts/types.ts\r\n```\r\n\r\n## Tests\r\n\r\nBefore running the tests, ensure that you have all the node.js dependencies\r\ninstalled by running `yarn` or `npm i`.\r\n\r\nThe tests check serialisation and deserialisation from generated TypeScript by\r\nround-tripping encoded data via stdio and asserting the expected values.\r\n\r\n## Prior Art\r\n\r\nThis builds on (ie. much TypeScript stolen from) the following projects.\r\n\r\n_The stated pros and cons are just personal opinion!_\r\n\r\n### [`ts-rust-bridge`](https://github.com/twop/ts-rust-bridge)\r\n\r\n### Pros:\r\n\r\n- Function based TypeScript API\r\n- Great ergonomics for enums with combination of `type` + `interface` + `module`\r\n\r\n### Cons:\r\n\r\n- Generates both Rust and TypeScript from a DSL. (**I want Rust to be the source\r\n  of truth**).\r\n- Does not use `const enum` for Unit enums\r\n\r\n### [`serde-reflection/serde-generate`](https://github.com/novifinancial/serde-reflection/pull/59)\r\n\r\n### Pros:\r\n\r\n- Uses `serde` so no messing around parsing Rust\r\n\r\n### Cons:\r\n\r\n- All types have to be run through the registry after build so wont work from `build.rs`\r\n- TypeScript classes wrap every type and use inheritance (ie. no `const enum`)\r\n- Runtime TypeScript is separate\r\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimfish%2Fbincode-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimfish%2Fbincode-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimfish%2Fbincode-typescript/lists"}