desktop-backend-tauri
Tauri Rust Backend Patterns
Quick Guide: Define commands with
#[tauri::command], register ingenerate_handler![]. UseState<T>for shared state (wrap mutable fields inMutex). Error types must implement bothserde::SerializeandDisplay-- usethiserrorfor ergonomic error enums. Async commands run on Tokio -- borrowed args (&str,State<'_, T>) requireResult<T, E>return type. Stream data to frontend viaChannel<T>(not events) for high throughput. Emit events withapp.emit()for fire-and-forget notifications.Current version: Tauri 2.x (stable). Async runtime is Tokio.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST register every command in tauri::generate_handler![] -- unregistered commands compile fine but silently fail at runtime)
(You MUST implement serde::Serialize on all error types returned from commands -- Tauri serializes errors across the IPC boundary)
(You MUST wrap mutable managed state in Mutex or RwLock -- commands run concurrently and State<T> requires Send + Sync)