Specta

Export Rust types to TypeScript, Swift, Go, OpenAPI, and other languages automatically.

Library
Cargo
v2.0.0-rc.25
626stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity96
Maintenance96
Community56
Maturity52
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture86
Code Quality84
Innovation84
Learning Curve74

Specta is a Rust crate that reflects your Rust structs, enums, and function signatures at compile time and exports matching type definitions to other languages — TypeScript and Swift are production-ready today, with Go, C#, Java, Kotlin, OpenAPI, JSON Schema, Zod, Python, and Rust-to-Rust exporters at varying levels of maturity. Types opt in via a #[derive(Type)] macro, after which any of Specta’s per-language exporter crates (specta-typescript, specta-swift, etc.) can turn the reflected type graph into idiomatic target-language code.

Specta is the foundational type-reflection layer underneath higher-level tools like tauri-specta (typed Tauri commands) and rspc (typed RPC APIs), letting Rust backends and their non-Rust frontends or clients share one canonical type definition instead of hand-duplicating DTOs.

What You Get

  • A #[derive(Type)] macro (via specta-macros) that reflects struct/enum shape, generics, and doc comments into a language-agnostic type graph
  • Function-signature reflection so Specta-aware tools (like tauri-specta) can generate typed call wrappers, not just data types
  • A family of per-language exporter crates: specta-typescript and specta-swift (stable), plus specta-go, specta-csharp, specta-java, specta-kotlin, specta-jsonschema, specta-zod, specta-python, specta-openapi, and specta-rust (partial/in-progress)
  • Wide coverage of common Rust ecosystem types (serde, chrono, uuid, etc.) out of the box so exported types match idiomatic Serde serialization
  • Type inference support for functions returning impl Type, avoiding explicit type annotations in many cases

Common Use Cases

  • Generating TypeScript types for a Rust backend’s API/IPC layer consumed by a JS/TS frontend (directly, or via tauri-specta)
  • Building a typed end-to-end RPC framework on top of Specta’s reflection (as rspc does)
  • Exporting OpenAPI or JSON Schema documents describing a Rust API’s request/response types
  • Sharing one canonical Rust type definition across multiple client languages (Swift, Kotlin, Go, Python) in a multi-platform app

Under The Hood

Architecture: The core specta crate defines a language-agnostic DataType/Type model (src/datatype.rs, src/type.rs) that a #[derive(Type)] proc macro (specta-macros) populates by reflecting Rust struct/enum definitions and function signatures (src/function.rs); each target language then lives in its own downstream crate (e.g. specta-typescript) that walks this shared DataType graph and renders it into that language’s syntax, keeping the reflection core decoupled from any single output format. Tech Stack: Pure Rust workspace (Cargo.toml with members set to specta, specta-*, tests, and examples) using proc-macros for the derive, with per-exporter crates depending only on the core specta crate plus target-format-specific logic (e.g. specta-jsonschema implements JSON Schema draft 7/2019-09/2020-12). Code Quality: The workspace enables strict Clippy lints (unwrap_used, panic, todo all set to warn) across all crates, has a dedicated tests/ workspace member with schema and typecheck fixtures (including a zod-typecheck suite), and documents implementation-status maturity per exporter (2 production-ready, 9 partial) directly in the README rather than overstating completeness. API Design: The primary surface is a single #[derive(Type)] attribute plus optional per-field attributes for renaming/skipping, mirroring Serde’s derive ergonomics closely so Rust developers already familiar with #[derive(Serialize)] need minimal new mental model to adopt Specta.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search