Tyzen β‘
Tyzen is a high-performance developer tool that bridges the gap between Rust and TypeScript. Its primary goal is to provide a seamless, type-safe development experience (DX) by automating the synchronization of data structures and API definitions.
While Tyzen was built with Tauri in mind, its core is a generic, lightning-fast type generator that can be used in any Rust/TS project.
β¨ Why Tyzen?
- π Performance: Generates complex TypeScript bindings in milliseconds.
- π οΈ Developer Experience (DX): Zero-config command registration and strongly-typed events.
- π¦ Transparency: Keeps your code clear and explicit.
- π Tauri Integration: First-class support for Tauri commands and events with automatic registration.
π Quick Start
1. Add Dependencies
For core type generation:
For Tauri integration (Optional):
2. Define Your Types (Rust)
Tyzen uses simple attributes to mark structs, enums, and functions.
use ;
// 1. Convert any Rust struct/enum to TS
// 2. Define a typed Event
3. Setup the Generator
In your main.rs (or any build/tool script), initialize the generator:
π Tauri Integration
For Tauri projects, tyzen-tauri provides a wrapper that automates command registration and event handling.
1. Define Tauri Commands
No stacked macros needed! The #[tyzen_tauri::command] macro automatically expands and registers your commands with Tauri under the hood.
// Marks for TS generation & auto-registers with Tauri
2. Setup Generator & Handler
π» Frontend Usage (TypeScript/React)
Tyzen creates a clean, intuitive API for your frontend.
import { useEffect, useState } from 'react';
import { commands, events } from "./bindings";
function App() {
const [status, setStatus] = useState("Ready");
useEffect(() => {
// 1. Call a command (Type-safe Promise)
commands.createUser("rzust").then(res => {
if (res.status === 'ok') console.log("Success:", res.data);
});
// 2. Listen to an event (Fluent API)
const unlisten = events.welcome.listen((payload) => {
setStatus(`Message: ${payload.message}`);
});
return () => { unlisten.then(f => f()); };
}, []);
return <h1>{status}</h1>;
}
π Feature Guide
Standard Type Conversion
Use #[derive(tyzen::Type)] on any Rust type. It supports primitives, Vec, Option, HashMap, and even complex Generics.
Tauri Commands
The #[tyzen_tauri::command] macro is the only attribute you need to declare a type-safe Tauri command. It automatically handles code generation and expands #[tauri::command] so there is zero boilerplate or stacked-macro footguns.
Typed Events
When you derive tyzen::Event, Tyzen adds a helper .emit(&handle) method to your struct:
let event = WelcomeEvent ;
event.emit.ok; // Correctly types the payload for the frontend
πΊοΈ Roadmap & Status
| Feature | Importance | Notes |
|---|---|---|
| Full Serde Parity | Implemented | flatten, alias, default, and rename_all support. Requires inter-type metadata. |
| Binary Data | Implemented | Automatically maps Vec<u8> or fields marked with #[tyzen(binary)] to Uint8Array with transparent hydration. |
| Result & Error | Implemented | Deep support for custom Rust error types and enum variant metadata blocks in frontend. |
| Constant Export | Implemented | Sync pub const logic values from Rust to TS. |
| Namespaces | Implemented | Organize types and commands into logical Models (SDK style). |
| Validation Sync | Core | Bridge validator rules (Rust) directly into Zod schemas (TS). |
| Zod Support | Will implement | Generate Zod schemas alongside types for runtime frontend validation. |
| Mock Client | Will implement | Generate mock JS/TS clients for testing/UI prototyping without the backend. |
| Doc Propagation | Transform Rust doc comments (///) into TSDoc (/** ... */). |
π¦ Packages
tyzen: The core engine for type conversion.tyzen-macro: Procedural macros forTypeandEvent.tyzen-tauri: Specialized integration for Tauri (commands, event emitters, and TS glue code).
π License
Distributed under the MIT / Apache-2.0 License.