百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

specta

> 编程语言
开源

轻松将您的 Rust 类型导出到其他语言

622 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

轻松将您的 Rust 类型导出到其他语言

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:

…

Then you can use Specta like following:

TypeScript Example

…

Multi-Language Export Example

You can export the same types to multiple languages:

rust
use specta::{Type, Types};
use specta_typescript::Typescript;
use specta_swift::Swift;

#[derive(Type)]
pub struct User {
    pub id: u32,
    pub name: String,
    pub email: Option,
}

fn main() {
    let types = Types::default()
        .register::();

    // Export to TypeScript (stable)
    Typescript::default()
        .export_to("./types.ts", &types)
        .unwrap();

    // Export to Swift (stable)
    Swift::default()
        .export_to("./Types.swift", &types)
        .unwrap();

    // Note: Other exporters are in development
}

A common use case is to export all types for which specta::Type is derived into a single file:

rust
//! NOTE: This example requires the `export` feature on the `specta` crate
use specta::Type;
use specta_typescript::Typescript;

#[derive(Type)]
pub enum MyEither {
    Left(L),
    Right(R),
}

#[derive(Type)]
pub struct GenericType {
    pub my_field: String,
    pub generic: A,
}

#[derive(Type)]
pub enum MyEnum {
    A,
    B,
    C,
}

#[derive(Type)]
#[specta(collect = false)]
pub struct DontExportMe {
    field: String,
}

fn main() {
    Typescript::default()
        .export_to("./bindings.ts", &specta::export())
        .unwrap();
}

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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustreflectionrspcrustrust-macro

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言