Skip to main content

Crate typebridge

Crate typebridge 

Source
Expand description

§typebridge

Cross-Language Type Synchronization SDK for Rust.

Define your types once in Rust. Get perfectly matching types in TypeScript, Python, Go, Swift, Kotlin, GraphQL, and JSON Schema — automatically, forever.

§Overview

typewriter eliminates the tedious work of keeping types in sync across languages. Annotate your Rust structs with #[derive(TypeWriter)] and #[sync_to(...)], and the types are automatically generated in all target languages on every build.

§Quick Start

use typebridge::TypeWriter;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, TypeWriter)]
#[sync_to(typescript, python, go)]
pub struct UserProfile {
    pub id: Uuid,
    pub email: String,
    pub age: Option<u32>,
}

On cargo build, this generates:

  • ./generated/typescript/user-profile.ts — TypeScript interface
  • ./generated/typescript/user-profile.schema.ts — Zod schema
  • ./generated/python/user_profile.py — Python Pydantic model
  • ./generated/go/user_profile.go — Go struct

§Supported Languages

LanguageFeature FlagOutput
TypeScripttypescript (default).ts interfaces + Zod schemas
Pythonpython (default).py Pydantic models
Gogo (default).go structs
Swiftswift (default).swift Codable structs
Kotlinkotlin (default).kt data classes
GraphQLgraphql (default).graphql SDL
JSON Schemajson_schema (default).schema.json

§Feature Flags

Disable languages you don’t need to reduce compile times:

[dependencies]
typebridge = { version = "0.5.0", default-features = false, features = ["typescript", "python"] }

§CLI

For project-wide generation, drift checking, and watch mode:

cargo install typebridge-cli

typewriter generate --all     # Generate all types
typewriter check --ci         # Check for drift
typewriter watch              # Watch for changes

See typebridge_cli for more.

Modules§

config
Re-export core types for advanced usage. Configuration parsing for typewriter.toml.
ir
Re-export core types for advanced usage. Internal Representation (IR) for typewriter.
mapper
Re-export core types for advanced usage. The TypeMapper trait — the core contract every language emitter must implement.
naming
Re-export core types for advanced usage. File naming utilities for converting type names to different case styles.

Structs§

EnumDef
Re-export core types for advanced usage. A complete enum definition in the IR.
FieldDef
Re-export core types for advanced usage. A single field inside a struct.
StructDef
Re-export core types for advanced usage. A complete struct definition in the IR.
TypewriterConfig
Re-export core types for advanced usage. Top-level configuration from typewriter.toml.
VariantDef
Re-export core types for advanced usage. A single enum variant.

Enums§

EnumRepr
Re-export core types for advanced usage. How the enum is represented in JSON (mirrors serde’s options).
FileStyle
Re-export core types for advanced usage. Supported file naming styles.
Language
Re-export core types for advanced usage. The target languages that typewriter can generate code for.
PrimitiveType
Re-export core types for advanced usage. Rust primitive types that map to language-specific equivalents.
TypeDef
Re-export core types for advanced usage. Top-level item — either a struct or an enum.
TypeKind
Re-export core types for advanced usage. Every Rust type is mapped to one of these variants.
VariantKind
Re-export core types for advanced usage. The kind of data an enum variant carries.

Traits§

TypeMapper
Re-export core types for advanced usage. The core trait that every language emitter must implement.

Functions§

to_file_style
Re-export core types for advanced usage. Convert a PascalCase name to the specified file style.

Derive Macros§

TypeWriter
Re-export the TypeWriter derive macro. Derive macro for typewriter type synchronization.