|
14 | 14 |
|
15 | 15 | ## Features |
16 | 16 |
|
17 | | - - Export structs and enums to [Typescript](https://www.typescriptlang.org) |
18 | | - - Get function types to use in libraries like [tauri-specta](https://github.com/oscartbeaumont/tauri-specta) |
19 | | - - Supports wide range of common crates in Rust ecosystem |
20 | | - - Supports type inference - can determine type of `fn demo() -> impl Type`. |
| 17 | +- Export structs and enums to multiple languages |
| 18 | +- Get function types to use in libraries like [tauri-specta](https://github.com/oscartbeaumont/tauri-specta) |
| 19 | +- Supports wide range of common crates in Rust ecosystem |
| 20 | +- Supports type inference - can determine type of `fn demo() -> impl Type` |
| 21 | + |
| 22 | +## Language Support |
| 23 | + |
| 24 | +| Language | Status | Exporter | Features | |
| 25 | +| --------------- | -------------- | ----------------------------------------------------------------- | ------------------------------------------------- | |
| 26 | +| **TypeScript** | ✅ **Stable** | [`specta-typescript`](https://crates.io/crates/specta-typescript) | Full type support, generics, unions | |
| 27 | +| **Swift** | ✅ **Stable** | [`specta-swift`](https://crates.io/crates/specta-swift) | Idiomatic Swift, custom Codable, Duration support | |
| 28 | +| **Rust** | 🚧 **Partial** | [`specta-rust`](https://crates.io/crates/specta-rust) | Basic types work, structs/enums in progress | |
| 29 | +| **OpenAPI** | 🚧 **Partial** | [`specta-openapi`](https://crates.io/crates/specta-openapi) | Primitives work, complex types in progress | |
| 30 | +| **Go** | 🚧 **Planned** | [`specta-go`](https://crates.io/crates/specta-go) | Go structs and interfaces | |
| 31 | +| **Kotlin** | 🚧 **Planned** | [`specta-kotlin`](https://crates.io/crates/specta-kotlin) | Kotlin data classes and sealed classes | |
| 32 | +| **JSON Schema** | 🚧 **Planned** | [`specta-jsonschema`](https://crates.io/crates/specta-jsonschema) | JSON Schema generation | |
| 33 | +| **Zod** | 🚧 **Planned** | [`specta-zod`](https://crates.io/crates/specta-zod) | Zod schema validation | |
| 34 | +| **Python** | 🚧 **Planned** | `specta-python` | Python dataclasses and type hints | |
| 35 | +| **C#** | 🚧 **Planned** | `specta-csharp` | C# classes and enums | |
| 36 | +| **Java** | 🚧 **Planned** | `specta-java` | Java POJOs and enums | |
| 37 | + |
| 38 | +### Legend |
| 39 | + |
| 40 | +- ✅ **Stable**: Production-ready with comprehensive test coverage |
| 41 | +- 🚧 **Partial**: Basic functionality implemented, complex types in progress |
| 42 | +- 🚧 **Planned**: In development or planned for future release |
| 43 | + |
| 44 | +## Implementation Status |
| 45 | + |
| 46 | +The Specta ecosystem is actively developed with varying levels of completeness: |
| 47 | + |
| 48 | +- **Production Ready (2)**: TypeScript and Swift exporters are fully functional with comprehensive test coverage |
| 49 | +- **Partially Implemented (2)**: Rust and OpenAPI exporters have basic functionality working, with complex types in progress |
| 50 | +- **Planned (7)**: Go, Kotlin, JSON Schema, Zod, Python, C#, and Java exporters are in development |
| 51 | + |
| 52 | +For the most up-to-date status of each exporter, check the individual crate documentation and issue trackers. |
21 | 53 |
|
22 | 54 | ## Ecosystem |
23 | 55 |
|
24 | 56 | Specta can be used in your application either directly or through a library which simplifies the process of using it. |
25 | 57 |
|
26 | | - - [rspc](https://github.com/oscartbeaumont/rspc) - Easily building end-to-end typesafe APIs |
27 | | - - [tauri-specta](https://github.com/oscartbeaumont/tauri-specta) - Typesafe Tauri commands and events |
28 | | - - [TauRPC](https://github.com/MatsDK/TauRPC) - Tauri extension to give you a fully-typed IPC layer. |
| 58 | +- [rspc](https://github.com/oscartbeaumont/rspc) - Easily building end-to-end typesafe APIs |
| 59 | +- [tauri-specta](https://github.com/oscartbeaumont/tauri-specta) - Typesafe Tauri commands and events |
| 60 | +- [TauRPC](https://github.com/MatsDK/TauRPC) - Tauri extension to give you a fully-typed IPC layer. |
29 | 61 |
|
30 | 62 | ## Usage |
31 | 63 |
|
32 | | -Add the [`specta`](https://docs.rs/specta) crate along with any Specta language exporter crate, for example [`specta-typescript`](https://docs.rs/specta-typescript). |
| 64 | +Add the [`specta`](https://docs.rs/specta) crate along with any Specta language exporter crate: |
33 | 65 |
|
34 | 66 | ```bash |
| 67 | +# Core Specta library |
35 | 68 | cargo add specta |
36 | | -cargo add specta_typescript |
| 69 | + |
| 70 | +# Language exporters (choose one or more) |
| 71 | +cargo add specta_typescript # TypeScript (stable) |
| 72 | +cargo add specta_swift # Swift (stable) |
| 73 | +cargo add specta_rust # Rust (partial - basic types) |
| 74 | +cargo add specta_openapi # OpenAPI/Swagger (partial - primitives) |
| 75 | +# cargo add specta_go # Go (planned) |
| 76 | +# cargo add specta_kotlin # Kotlin (planned) |
| 77 | +# cargo add specta_jsonschema # JSON Schema (planned) |
| 78 | +# cargo add specta_zod # Zod schemas (planned) |
37 | 79 | ``` |
38 | 80 |
|
39 | 81 | Then you can use Specta like following: |
40 | 82 |
|
| 83 | +### TypeScript Example |
| 84 | + |
41 | 85 | ```rust |
42 | 86 | use specta::{Type, TypeCollection}; |
43 | 87 | use specta_typescript::Typescript; |
@@ -89,6 +133,40 @@ export type TypeOne = { a: string; b: GenericType<number>; cccccc: MyEnum }; |
89 | 133 |
|
90 | 134 | ``` |
91 | 135 |
|
| 136 | +### Multi-Language Export Example |
| 137 | + |
| 138 | +You can export the same types to multiple languages: |
| 139 | + |
| 140 | +```rust |
| 141 | +use specta::{Type, TypeCollection}; |
| 142 | +use specta_typescript::Typescript; |
| 143 | +use specta_swift::Swift; |
| 144 | + |
| 145 | +#[derive(Type)] |
| 146 | +pub struct User { |
| 147 | + pub id: u32, |
| 148 | + pub name: String, |
| 149 | + pub email: Option<String>, |
| 150 | +} |
| 151 | + |
| 152 | +fn main() { |
| 153 | + let types = TypeCollection::default() |
| 154 | + .register::<User>(); |
| 155 | + |
| 156 | + // Export to TypeScript (stable) |
| 157 | + Typescript::default() |
| 158 | + .export_to("./types.ts", &types) |
| 159 | + .unwrap(); |
| 160 | + |
| 161 | + // Export to Swift (stable) |
| 162 | + Swift::default() |
| 163 | + .export_to("./Types.swift", &types) |
| 164 | + .unwrap(); |
| 165 | + |
| 166 | + // Note: Other exporters are in development |
| 167 | +} |
| 168 | +``` |
| 169 | + |
92 | 170 | A common use case is to export all types for which `specta::Type` is derived into a single file: |
93 | 171 |
|
94 | 172 | ```rust |
|
0 commit comments