gear-mesh ⚙️
Next-generation Rust to TypeScript type definition sharing library.
Features
- 🏷️ Branded Types: Convert Rust newtype patterns to TypeScript Branded Types
- 📝 Doc Comments: Automatically convert Rust doc comments to JSDoc
- ✅ Validation: Generate Zod schemas with validation rules
- 🔢 BigInt Support: Automatically use
bigintforu64/i64 - 🎯 Type Safety: Full type safety from Rust to TypeScript
Quick Start
Installation
[]
= "0.1"
Basic Usage
use GearMesh;
;
/// User information
Generated TypeScript
// 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(),
});
Validation Rules
| 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]/) |
Configuration
use ;
let config = new
.with_bigint // Use bigint for u64/i64
.with_zod // Generate Zod schemas
.with_validation // Include validation rules
.with_branded // Generate Branded Types
.with_jsdoc; // Include JSDoc comments
generate_with_config
.expect;
Examples
See the examples directory for complete examples:
- simple-bigint: Basic BigInt usage
- axum-react: Full-stack application with Axum backend and React frontend
Comparison with Existing Crates
| 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 |
Documentation
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.