Windsurf rules for Rust: borrowing-first function signatures, typed errors with thiserror, anyhow in binaries, Tokio entry points and clippy-checked performance work.
.devin/rules/rust-development-in-windsurf.md. Downloaded files need to be placed in that repository path.---
trigger: glob
globs: "**/*"
---
Apply these rules to Rust code.
## Ownership and borrowing
```rust
// Borrow when you only read
fn checksum(data: &[u8]) -> u32 {
data.iter().map(|&b| u32::from(b)).sum()
}
// Mutable reference when you modify in place
fn push_terminator(data: &mut Vec<u8>) {
data.push(0);
}
```
- Accept `&str` and `&[T]` rather than `&String` and `&Vec<T>`; take ownership only when the function stores or consumes the value.
## Error handling
```rust
use std::collections::HashMap;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AppError {
#[error("not found: {0}")]
NotFound(String),
#[error("invalid input: {0}")]
InvalidInput(String),
}
pub fn get_user(users: &HashMap<String, User>, id: &str) -> Result<User, AppError> {
users
.get(id)
.cloned()
.ok_or_else(|| AppError::NotFound(id.to_string()))
}
```
- Libraries return typed errors (`thiserror`); binaries use `anyhow::Result` and add `.context(...)`. Do not import `anyhow::Result` into modules that also return typed errors, to avoid confusing two `Result` types.
## Async patterns
```rust
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let data = fetch_data().await?;
println!("{} records", data.len());
Ok(())
}
```
- Do not block inside async functions; use `tokio::task::spawn_blocking` for blocking work.
## Performance
- Prefer iterators over manual index loops; they are as fast and avoid bounds-check bugs.
- Avoid unnecessary clones and allocations; borrow or reuse buffers.
- Profile (criterion benchmarks, a profiler) before optimizing.
- Run `cargo fmt`, `cargo clippy` and `cargo test` before proposing changes.
Cursor rules for Rust systems code: borrowing-first APIs, thiserror/anyhow error layers, Tokio async with correct mutex choice, allocation-aware performance and project layout.
CLAUDE.md rules for Rust 2024 crates with borrow-first APIs, Cow, thiserror 2 typed errors kept apart from anyhow, sqlx lookups and non-blocking Tokio workers.
Add performance monitoring and analytics
Windsurf
systems
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Windsurf generated a get_user that returns a borrowed &User where User is expected, references an undefined users map, and imports anyhow::Result alongside thiserror types.
Fix src/users.rs and src/main.rs following the Rust development rule.
get_user takes &HashMap<String, User> and &str, returns Result<User, AppError> via get().cloned().ok_or_else(...); main returns anyhow::Result<()> without a conflicting import; the answer says to run cargo clippy and cargo test.
Windsurf's rules documentation (docs.windsurf.com/windsurf/cascade/memories) now redirects to Devin documentation, which describes rules for the Devin Local agent in Devin Desktop. Current rules live in .devin/rules/*.md with a trigger setting, and the legacy Windsurf files (.windsurf/rules/*.md, .windsurf/global_rules.md and .windsurfrules) are still imported by default. AGENTS.md files are read as always-on rules.
.devin/rules/rust-development-in-windsurf.mdStarting point, not a tested configuration for your repository. Applied when files matching globs are involved (trigger: glob). Review the instructions, adapt the file paths and run your project's existing checks.
---
trigger: glob
globs: "**/*"
---
Apply these rules to Rust code.
## Ownership and borrowing
```rust
// Borrow when you only read
fn checksum(data: &[u8]) -> u32 {
data.iter().map(|&b| u32::from(b)).sum()
}
// Mutable reference when you modify in place
fn push_terminator(data: &mut Vec<u8>) {
data.push(0);
}
```
- Accept `&str` and `&[T]` rather than `&String` and `&Vec<T>`; take ownership only when the function stores or consumes the value.
## Error handling
```rust
use std::collections::HashMap;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AppError {
#[error("not found: {0}")]
NotFound(String),
#[error("invalid input: {0}")]
InvalidInput(String),
}
pub fn get_user(users: &HashMap<String, User>, id: &str) -> Result<User, AppError> {
users
.get(id)
.cloned()
.ok_or_else(|| AppError::NotFound(id.to_string()))
}
```
- Libraries return typed errors (`thiserror`); binaries use `anyhow::Result` and add `.context(...)`. Do not import `anyhow::Result` into modules that also return typed errors, to avoid confusing two `Result` types.
## Async patterns
```rust
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let data = fetch_data().await?;
println!("{} records", data.len());
Ok(())
}
```
- Do not block inside async functions; use `tokio::task::spawn_blocking` for blocking work.
## Performance
- Prefer iterators over manual index loops; they are as fast and avoid bounds-check bugs.
- Avoid unnecessary clones and allocations; borrow or reuse buffers.
- Profile (criterion benchmarks, a profiler) before optimizing.
- Run `cargo fmt`, `cargo clippy` and `cargo test` before proposing changes.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
The docs recommend keeping rules short and specific. The current docs say AGENTS.md, AGENTS.local.md and AGENT.md are read as always-on rules, including files in subdirectories. Use .devin/rules/ when you need glob, model-decision or manual triggers.
Documentation checked 2026-11-05: Devin docs: Local customizations (redirect target of Windsurf memories docs)Windsurf docs: Cascade memories (redirects)
Cursor rules for Rust systems code: borrowing-first APIs, thiserror/anyhow error layers, Tokio async with correct mutex choice, allocation-aware performance and project layout.
CLAUDE.md rules for Rust 2024 crates with borrow-first APIs, Cow, thiserror 2 typed errors kept apart from anyhow, sqlx lookups and non-blocking Tokio workers.
Add performance monitoring and analytics