| Crates.io | gear-mesh |
| lib.rs | gear-mesh |
| version | 0.1.0 |
| created_at | 2025-12-28 03:53:06.244155+00 |
| updated_at | 2025-12-28 03:53:06.244155+00 |
| description | Next-generation Rust to TypeScript type definition sharing library |
| homepage | https://github.com/UtakataKyosui/GearMesh |
| repository | https://github.com/UtakataKyosui/GearMesh |
| max_upload_size | |
| id | 2008200 |
| size | 26,849 |
Next-generation Rust to TypeScript type definition sharing library.
bigint for u64/i64[dependencies]
gear-mesh = "0.1"
use gear_mesh::GearMesh;
#[derive(GearMesh)]
#[gear_mesh(branded)]
struct UserId(i32);
/// User information
#[derive(GearMesh)]
struct User {
/// User's unique identifier
id: UserId,
/// User's display name
#[validate(length(min = 1, max = 20))]
name: String,
/// User's email address
#[validate(email)]
email: String,
}
fn main() {
// Generate TypeScript types
gear_mesh::generate_types_to_dir("generated")
.expect("Failed to generate TypeScript types");
}
// Branded Type
type Brand<T, B> = T & { readonly __brand: B };
export type UserId = Brand<number, "UserId">;
// Interface with JSDoc
/**
* User information
*/
export interface User {
/** User's unique identifier */
id: UserId;
/** User's display name */
name: string;
/** User's email address */
email: string;
}
// Zod Schema with Validation
export const UserSchema = z.object({
id: z.number(),
name: z.string().min(1).max(20),
email: z.string().email(),
});
| Rule | Attribute | Generated Zod |
|---|---|---|
| Range | #[validate(range(min = 0, max = 100))] |
.min(0).max(100) |
| Length | #[validate(length(min = 1, max = 20))] |
.min(1).max(20) |
#[validate(email)] |
.email() |
|
| URL | #[validate(url)] |
.url() |
| Pattern | #[validate(pattern = "^[A-Z]")] |
.regex(/^[A-Z]/) |
use gear_mesh::{GeneratorConfig, generate_with_config};
let config = GeneratorConfig::new()
.with_bigint(true) // Use bigint for u64/i64
.with_zod(true) // Generate Zod schemas
.with_validation(true) // Include validation rules
.with_branded(true) // Generate Branded Types
.with_jsdoc(true); // Include JSDoc comments
gear_mesh::generate_with_config("generated", config)
.expect("Failed to generate");
See the examples directory for complete examples:
| Feature | ts-rs | typeshare | specta | gear-mesh |
|---|---|---|---|---|
| Basic type conversion | ✅ | ✅ | ✅ | ✅ |
| Branded Types | ❌ | ❌ | ❌ | ✅ |
| Doc comment conversion | ❌ | ❌ | ❌ | ✅ |
| Zod Schema | ❌ | ❌ | ❌ | ✅ |
| Validation embedding | ❌ | ❌ | ❌ | ✅ |
| Auto BigInt | Manual | Manual | Manual | ✅ Auto |
Licensed under either of:
at your option.
Contributions are welcome! Please see CONTRIBUTING.md for details.