Skip to content

Commit 30bc3cc

Browse files
Merge pull request #405 from jamiepine/swift
Specta Swift
2 parents a147fce + 161e273 commit 30bc3cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+8996
-185
lines changed

Cargo.lock

Lines changed: 38 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,74 @@
1414

1515
## Features
1616

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.
2153

2254
## Ecosystem
2355

2456
Specta can be used in your application either directly or through a library which simplifies the process of using it.
2557

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.
2961

3062
## Usage
3163

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:
3365

3466
```bash
67+
# Core Specta library
3568
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)
3779
```
3880

3981
Then you can use Specta like following:
4082

83+
### TypeScript Example
84+
4185
```rust
4286
use specta::{Type, TypeCollection};
4387
use specta_typescript::Typescript;
@@ -89,6 +133,40 @@ export type TypeOne = { a: string; b: GenericType<number>; cccccc: MyEnum };
89133

90134
```
91135

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+
92170
A common use case is to export all types for which `specta::Type` is derived into a single file:
93171

94172
```rust

0 commit comments

Comments
 (0)