← ClaudeAtlas

rust-stylelisted

Rust coding style guide. Apply automatically when writing or modifying Rust code. Enforces for-loops over iterators, let-else for early returns, variable shadowing, newtypes, explicit matching, and minimal comments.
paulnsorensen/hallouminate · ★ 0 · AI & Automation · score 66
Install: claude install-skill paulnsorensen/hallouminate
# Rust Coding Style Apply these rules when writing or modifying any Rust code. ## Control Flow: Use `for` Loops, Not Iterator Chains Write `for` loops with mutable accumulators instead of iterator combinators. ```rust // DO let mut results = Vec::new(); for item in items { if item.is_valid() { results.push(item.process()); } } // DON'T let results: Vec<_> = items .iter() .filter(|item| item.is_valid()) .map(|item| item.process()) .collect(); ``` ```rust // DO let mut total = 0; for value in values { total += value.amount(); } // DON'T let total: i64 = values.iter().map(|v| v.amount()).sum(); ``` ```rust // DO let mut found = None; for item in items { if item.matches(query) { found = Some(item); break; } } // DON'T let found = items.iter().find(|item| item.matches(query)); ``` ## Early Returns: Use `let ... else` Use `let ... else` to extract values and exit early on failure. This keeps the happy path unindented. ```rust // DO let Some(user) = get_user(id) else { return Err(Error::NotFound); }; let Ok(session) = user.active_session() else { return Err(Error::NoSession); }; // continue with user and session // DON'T if let Some(user) = get_user(id) { if let Ok(session) = user.active_session() { // deeply nested code } else { return Err(Error::NoSession); } } else { return Err(Error::NotFound); } ``` ```rust // DO let Some(value) = maybe_value else { continue }; let