Features
- Export structs and enums to multiple languages
- Get function types to use in libraries like tauri-specta
- Supports wide range of common crates in Rust ecosystem
- Supports type inference - can determine type of
fn demo() -> impl Type
Language Support
| Language | Status | Exporter | Features |
|---|---|---|---|
| TypeScript | ✅ Stable | specta-typescript |
Full type support, generics, unions |
| Swift | ✅ Stable | specta-swift |
Idiomatic Swift, custom Codable, Duration support |
| Rust | 🚧 Partial | specta-rust |
Rust source, modules, generics; structural wire-only shapes error |
| OpenAPI | 🚧 Partial | specta-openapi |
OpenAPI 3.0 schemas, generics, JSON and YAML |
| Go | 🚧 Partial | specta-go |
Structs, generics, string enums, layouts, Serde |
| Kotlin | 🚧 Partial | specta-kotlin |
Data/sealed classes, generics, optional Kotlinx |
| JSON Schema | 🚧 Partial | specta-jsonschema |
Draft 7/2019-09/2020-12, generics, Serde |
| Zod | 🚧 Partial | specta-zod |
Zod 4 schemas, inferred types, generics, layouts |
| Valibot | 🚧 Partial | specta-valibot |
Valibot schemas, inferred types, generics, layouts |
| Python | 🚧 Partial | specta-python |
Python 3.13 TypedDicts and type hints |
| C# | 🚧 Partial | specta-csharp |
Records, enums, generics, namespaces, file layouts |
| Java | 🚧 Partial | specta-java |
Java 17 records, enums, and sealed interfaces |
Legend
- ✅ Stable: Production-ready with comprehensive test coverage
- 🚧 Partial: Basic functionality implemented, complex types in progress
Implementation Status
The Specta ecosystem is actively developed with varying levels of completeness:
- Production Ready (2): TypeScript and Swift exporters are fully functional with comprehensive test coverage
- Partially Implemented (10): Rust, OpenAPI, Go, C#, Java, Kotlin, JSON Schema, Zod, Valibot, and Python have broad type support but are still stabilizing
- Planned (0): All currently listed exporters have an initial implementation
For the most up-to-date status of each exporter, check the individual crate documentation and issue trackers.
Ecosystem
Specta can be used in your application either directly or through a library which simplifies the process of using it.
- rspc - Easily building end-to-end typesafe APIs
- tauri-specta - Typesafe Tauri commands and events
- TauRPC - Tauri extension to give you a fully-typed IPC layer.
Usage
Add the specta crate along with any Specta language exporter crate:
# Core Specta library
# Language exporters (choose one or more)
Then you can use Specta like following:
TypeScript Example
use ;
use Typescript;
Multi-Language Export Example
You can export the same types to multiple languages:
use ;
use Typescript;
use Swift;
A common use case is to export all types for which specta::Type is derived into a single file:
//! NOTE: This example requires the `export` feature on the `specta` crate
use Type;
use Typescript;
Check out the docs for more information.
Motivation
This library was originally created to power the type exporting functionality of rspc, but after building it we realized that it could be useful for other projects as well so we decided to move it into a dedicated library.
A huge thanks to Brendonovich for doing a heap of early development on this library.
Releasing
Publishing to crates.io uses
crates.io trusted publishing: the
release workflow exchanges its GitHub OIDC identity for a short-lived crates.io
token, so no long-lived CARGO_REGISTRY_TOKEN is stored in this repository or
in Actions secrets.
One-time setup — a crate owner adds a trusted publisher in the crates.io UI
(the crate's Settings → Trusted Publishing) for every crate in the workspace.
These values must match .github/workflows/release.yml exactly, or the token
exchange is refused:
| Field | Value |
|---|---|
| Owner | specta-rs |
| Repository | specta |
| Workflow filename | release.yml |
| Environment | release |
The workflow publishes the whole workspace, so each of the following crates needs
its own trusted publisher: specta, specta-macros, specta-serde,
specta-util, specta-typescript, specta-swift, specta-openapi,
specta-jsonschema, specta-kotlin, specta-csharp, specta-go,
specta-python, specta-java, specta-zod, specta-valibot, specta-rust and
specta-rescript.
A trusted publisher can only be configured once a crate exists on crates.io, and
the initial publish requires an API token. specta-valibot, specta-rust and
specta-rescript have never been released, so publish each of them once from your
machine before adding its trusted publisher.
Adding required reviewers to the release GitHub environment is recommended: it
turns publishing into an approved action rather than something any tag push does.
Cutting a release:
-
Bump the
versionof every workspace crate (the tag names thespectacrate version) and merge tomain. The exporters pinspectato an exact version, so each one has to be republished wheneverspectachanges, and Cargo refuses to publish a version that already exists on crates.io. -
Tag the merge commit and push the tag:
The release workflow then verifies the release (the tag matches the specta
crate version, and the workspace builds and tests), publishes every crate to
crates.io, and creates the GitHub release.