Typesafe Tauri Commands.
Warning: This repo is under heavy development. Things may change, and quickly.
```bash pnpm i tauri-specta
cargo add tauri-specta ```
```rust use specta::Type; use serde::{Deserialize, Serialize};
// The specta::Type
macro allows us to understand your types
// We implement specta::Type
on primitive types for you.
// If you want to use a type from an external crate you may need to enable the feature on Specta.
pub struct MyCustomReturnType { pub foo: String, pub bar: i32, }
pub struct MyCustomArgumentType { pub foo: String, pub bar: i32, } ```
```rust
fn greet3() -> MyStruct { MyStruct { some_field: "Hello World".into(), } } ```
```rust // this example exports your types on startup when in debug mode or in a unit test. You can do whatever.
fn main() { #[cfg(debugassertions)] exporttots(collatetypes![greet, greet2, greet3], "../src/bindings.ts").unwrap(); }
fn exportbindings() { exporttots(collatetypes![greet, greet2, greet3], "../src/bindings.ts").unwrap(); } ```
```ts import { Commands } from "./bindings"; // This should point to the file we export from Rust
const t = typedInvoke
await t.invoke("greet", { name: 42 }); ```
Run the example:
bash
pnpm i
pnpm package build
cd example/
pnpm tauri dev