| Crates.io | gents |
| lib.rs | gents |
| version | 1.0.4 |
| created_at | 2022-09-04 11:07:38.171011+00 |
| updated_at | 2025-09-02 02:25:44.433457+00 |
| description | generate Typescript interfaces from Rust code |
| homepage | |
| repository | https://github.com/ImJeremyHe/gents |
| max_upload_size | |
| id | 658243 |
| size | 70,177 |
gents is a tool for generating Typescript interfaces from Rust code.
It bridges the gap between Rust backends and TypeScript frontends by automatically generating type definitions, making it easy to use serde-json for communication between the two languages without manually maintaining duplicate type stubs.
Why use gents?
gents lets you iterate quickly without worrying about type mismatches.gents makes cross-language type safety effortless.Typical scenarios where gents shines:
This tool is designed for LogiSheets and is inspired by ts-rs. Many thanks to them!
Your issues and PRs are welcome!
gents (Quickstart & Advanced)In your Cargo.toml:
[dev-dependencies]
gents = "1.0"
gents_derives = "1.0"
Use gents_derives::TS and specify the output file:
use gents_derives::TS;
#[derive(TS)]
#[ts(file_name = "person.ts", rename_all = "camelCase")]
pub struct Person {
pub age: u16,
pub en_name: String,
}
#[derive(TS)]
#[ts(file_name = "group.ts", rename_all = "camelCase")]
pub struct Group {
pub name: String,
pub capacity: u16,
pub members: Vec<Person>,
pub leader: Option<Person>,
}
You can use rename_all and rename for field naming policies.
Write a binary or unit test:
#[ignore]
#[test]
fn gents() {
use gents::FileGroup;
let mut group = FileGroup::new();
// Add your root types; dependencies will be included automatically
group.add::<Group>();
// The second argument controls whether to generate index.ts
group.gen_files("outdir", false);
}
Since Group has dependencies on Person, gents will automatically include Person in the generated files.
cargo test -- --ignored to generate files..ts files will be placed in the directory you specify (e.g., outdir).gen_files to true, an index.ts exporting all types will be generated..ts files to your frontend project (or link via a monorepo).FileGroup, all of its dependencies (other structs/enums it uses) are automatically included.ts-rs?ts-rs generates the files when running cargo test and in this way we must
commit those generated files into our repo.
It is not necessary and is even an obstacle when we use other build tools like bazel.
gents acts as a binary to generate Typescript files.
gents introduces a concept Group that from all the members in
this group files generated will be placed in the same directory. Group is seperate from the other group even though they can share some
dependecies. Therefore, gents requires you to specify the file_name on structs
or enums and to specify the dir on group, while ts-rs requires specifing the path on every item.
gents helps you manage the export files. And it gathers all the dependencies automatically.
gents is well support for referencing other crates.
Code generated by ts-rs is not match our coding style.