gear-mesh

Crates.iogear-mesh
lib.rsgear-mesh
version0.1.0
created_at2025-12-28 03:53:06.244155+00
updated_at2025-12-28 03:53:06.244155+00
descriptionNext-generation Rust to TypeScript type definition sharing library
homepagehttps://github.com/UtakataKyosui/GearMesh
repositoryhttps://github.com/UtakataKyosui/GearMesh
max_upload_size
id2008200
size26,849
ウタカタキョウスイ (UtakataKyosui)

documentation

README

gear-mesh ⚙️

Next-generation Rust to TypeScript type definition sharing library.

Crates.io Documentation Rust License

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 bigint for u64/i64
  • 🎯 Type Safety: Full type safety from Rust to TypeScript

Quick Start

Installation

[dependencies]
gear-mesh = "0.1"

Basic Usage

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");
}

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)
Email #[validate(email)] .email()
URL #[validate(url)] .url()
Pattern #[validate(pattern = "^[A-Z]")] .regex(/^[A-Z]/)

Configuration

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");

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:

at your option.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Commit count: 0

cargo fmt