Home › Tauri › Tauri 2 Rust backend rules

Tauri 2 Rust backend rules

Cursor rules for the Rust side of Tauri 2 apps: commands, typed errors, state, plugins, and capability files.

CursorTauri

How to use

Save this as .cursor/rules/tauri-rust.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.cursor/rules/tauri-rust.mdcDownload  
---
description: Tauri 2 Rust backend conventions
globs: ["src-tauri/**/*.rs","src-tauri/capabilities/*.json","src-tauri/tauri.conf.json"]
alwaysApply: false
---

# Tauri 2 (Rust side)

- Entry in `src-tauri/src/lib.rs` (`pub fn run()`), with `main.rs` calling it so mobile targets work.
- Builder pattern: `.plugin(...)` for each plugin, `.manage(AppState::default())`, `.invoke_handler(tauri::generate_handler![...])`, `.setup(|app| {...})`.
- Commands: `#[tauri::command] async fn save_note(state: State<'_, AppState>, note: NoteInput) -> Result<Note, AppError>`. Arguments are camelCase on the JS side by default.
- `AppError` uses `thiserror` and implements `serde::Serialize` (serialize to a string or `{ kind, message }`) so the frontend gets a clean rejection.
- State uses `std::sync::Mutex` for short critical sections or `tokio::sync::Mutex` if held across `.await`.
- Emit progress with `app.emit("export-progress", payload)`; stream large data with `tauri::ipc::Channel` instead of huge return values.
- Every plugin or command a window can call must be allowed in `src-tauri/capabilities/<window>.json`; custom commands get permissions via `build.rs`/`permissions/` when using app-level permissions. Keep scopes narrow (e.g. `$APPDATA/**`).
- File paths from the frontend are untrusted: resolve against `app.path().app_data_dir()` and reject traversal.
- No `unwrap()` in commands; use `?`.

## Done when
`cargo fmt --check`, `cargo clippy -- -D warnings`, and `cargo test` pass in `src-tauri/`.

Related rules

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Cloudflare Agents SDK rules

Cursor rules for stateful AI agents on Cloudflare (agents package): Durable Object state, SQL, scheduling, and WebSockets.

CursorCloudflare Workers / Hono

Convex backend rules

Cursor rules for Convex backends: schema, validated queries/mutations/actions, indexes, and auth checks.

CursorConvex

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.