Crate gear_mesh

Crate gear_mesh 

Source
Expand description

§gear-mesh

Next-generation Rust to TypeScript type definition sharing library.

§Features

  • Type Conversion: Automatic Rust → TypeScript type conversion
  • Branded Types: Newtype pattern → TypeScript Branded Types
  • Doc Comments: Rust doc comments → JSDoc
  • BigInt Support: Automatic i64/u64 → bigint conversion
  • Validation: Runtime validation function generation
  • Serde Integration: Full serde attribute support

§Quick Start

use gear_mesh::GearMesh;

#[derive(GearMesh)]
#[gear_mesh(branded)]
struct UserId(i32);

#[derive(GearMesh)]
struct User {
    id: UserId,
    name: String,
    email: Option<String>,
}

Generated TypeScript:

type Brand<T, B> = T & { readonly __brand: B };

export type UserId = Brand<number, "UserId">;
export const UserId = (value: number): UserId => value as UserId;

export interface User {
    id: UserId;
    name: string;
    email?: string | null;
}

§CLI Usage

Install the CLI tool:

cargo install gear-mesh-cli

Generate TypeScript definitions:

gear-mesh generate --input src --output bindings
gear-mesh watch --input src --output bindings

§Configuration

Create gear-mesh.toml:

[generator]
use_bigint = true
generate_branded = true
generate_jsdoc = true

[paths]
input = "src"
output = "bindings"

Re-exports§

pub use inventory;

Modules§

utils

Macros§

export_types
Export types macro for compile-time TypeScript generation

Structs§

BrandedTypeGenerator
Generator for Branded Types
DocComment
ドキュメントコメント
EnumType
列挙型
EnumVariant
列挙型のバリアント
FieldInfo
フィールド情報
GearMeshType
gear-mesh型の中間表現
GeneratorConfig
生成設定
GenericParam
ジェネリクスパラメータ
NewtypeType
新型パターン
SerdeFieldAttrs
serdeフィールド属性
StructType
構造体型
TypeAttributes
型の属性
TypeInfo
Type information for automatic collection via inventory
TypeRef
型参照
TypeScriptGenerator
TypeScript生成器
ValidationGenerator
Generator for Zod validation schemas

Enums§

EnumRepresentation
列挙型の表現方式
PrimitiveType
プリミティブ型
TypeKind
型の種類
ValidationRule
バリデーションルール
VariantContent
バリアントの内容

Traits§

GearMeshExport
Trait for types that can be exported to TypeScript

Functions§

extract_type_dependencies
Extract all custom type names referenced by a type
generate_types
Generate TypeScript definitions for all registered types
generate_types_to_dir
Generate TypeScript definitions to separate files
register_output
Register an output path and generate types if this is the first time

Derive Macros§

GearMesh
GearMesh derive macro