Rust programming style guide and conventions. Use this skill when writing, reviewing, or modifying Rust code...
Quick reference for project-specific Rust conventions. Load reference files for detailed examples.
String::from("...") instead of "...".to_string()String::new() instead of "".to_string()let foo: Vec<_> = items.collect()let foo = items.collect::<Vec<_>>()Prefer let Some(value) = option else { ... } over .is_none() + .unwrap()
Avoid array indexing. Use iterator methods: .enumerate(), .iter().map()
See references/indexing-patterns.md for detailed examples
When a type is namespaced by its module, don't repeat context:
storage::CasStorage or storage::DiskStorage — stutters "storage"storage::Disk — describes implementation (see courier/src/storage.rs:54)db::PostgresDatabase — stutters "database"db::Postgres — describes implementation (see courier/src/db.rs:29)Use single canonical variant with alias functions instead of separate variants for the same concept
See references/naming.md for complete guidelines
test_formats_str → ✅: formatsPrefer direct imports over fully qualified paths unless ambiguous:
// ✅ Prefer
use client::courier::v1::{Key, cache::ArtifactFile};
let key = Key::from_hex(&hex_string)?;
// ❌ Avoid
let key = client::courier::v1::Key::from_hex(&hex_string)?;
mod.rs. Always prefer my_module.rs + my_module/other_file.rsInline rust variables in format strings if possible:
format!("Hello, {name}")format!("Hello, {}", user.name())cargo add instead of manual Cargo.toml editscargo autoinherit after adding packages (if workspace uses inheritance)make format (uses nightly rustfmt)make checkmake check-fixmake precommit (runs machete-fix, autoinherit, check-fix, format, sqlx-prepare)Itertools::sorted over Vec::sort for iterator chainsPrefer streaming over buffered by default. Use traits: AsyncRead, AsyncWrite, Read, Write
color-eyre for errors and reportingResult for recoverable errorsDon't bold bullet points in markdown:
- **Hook**: message- Hook: messageAvoid "space dash space" pattern in prose, use colon instead:
Load these for detailed examples and patterns:
references/indexing-patterns.md - Array indexing alternatives with iterator methodsreferences/naming.md - Complete naming conventions with examplesreferences/control-flow.md - Control flow patterns and examplesInvoke when: