godmode:rust-conventions
Skill1 starsChanged 56 days agoMITView on GitHub
Rust coding conventions and best practices for all *.rs files in this workspace. Reference when writing new Rust code, reviewing a PR, or deciding between implementation approaches. Covers naming, ownership, error handling, API design, testing, and project organisation — based on the Rust API Guidelines, RFC 430, and idiomatic community standards.
In this repository76 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- godmode:agent-governanceSkill
- godmode:agent-improvement-loopSkill
- agents-skill-saveSkill
- baml-add-typesSkill
- godmode:brainstormSkill
- godmode:capSkill
- godmode:changelogSkill
- godmode:ci-fixSkill
- godmode:code-reviewSkill
- godmode:context-mapSkill
- godmode:cross-issueSkill
- godmode:crs-discoverSkill
- godmode:crs-hook-testingSkill
- godmode:crs-installSkill
- godmode:crs-propose-rulesSkill
- godmode:crs-validateSkill
- godmode:dead-codeSkill
- godmode:decomposeSkill
- godmode:dep-auditSkill
- godmode:dep-bumpSkill
- godmode:designSkill
- devloop-session-primerSkill
- godmode:dialecticSkill
- godmode:doc-maintainerSkill
- godmode:doc-reviewSkill
- godmode:doc-syncSkill
- godmode:doc-writerSkill
- doob-db-inspectorSkill
- doob-release-managerSkill
- godmode:doublecheckSkill
- dual-forge-pr-mergeSkill
- gh-bulk-issuesSkill
- godmode:health-scoreSkill
- godmode:ingestSkill
- godmode:introspectionSkill
- godmode:issue-triageSkill
- godmode:memory-bankingSkill
- godmode:mergeSkill
- godmode:mini-context-graphSkill
- godmode:mistake-trackerSkill
- godmode:moaSkill
- notfiles-release-workflowSkill
- godmode:observability-as-infrastructureSkill
- godmode:parallel-agentsSkill
- godmode:pattern-learnerSkill
- planning-with-cruxSkill
- godmode:pr-authorSkill
- godmode:receiving-reviewSkill
- godmode:refactoringSkill
- godmode:release-notesSkill
- release-readiness-checkSkill
- remote-upstream-triageSkill
- repo-gap-backlogSkill
- rustqualSkill
- rustqual-workspaceSkill
- rust-release-workflow-authorSkill
- godmode:self-reflectSkill
- session-wrap-commit-pushSkill
- godmode:systematic-debuggingSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
41 rules. About 0 are common, 10 are distinctive, and 31 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
31
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
Follow RFC 430 naming conventions throughout:
- Very specific: line 36
Prefer &T over cloning unless ownership transfer is required.
- Very specific: line 37
Use &mut T when you need to mutate borrowed data.
- Distinctive: line 42
Prefer borrowing and zero-copy operations to avoid unnecessary allocations.
- Very specific: line 43
Use &str instead of String for function parameters when ownership is not required.
- Very specific: line 49
Use Result<T, E> for all recoverable errors.
- Very specific: line 51
Use the ? operator for error propagation.
- Very specific: line 53
Create custom error types with thiserror.
- Very specific: line 55
Use Option<T> for values that may legitimately be absent.
- Distinctive: line 80
Use iterators instead of index-based loops — they are often faster, safer, and more expressive.
- Very specific: line 82
Avoid premature .collect() — keep iterator chains lazy until a collection is actually needed.
- Very specific: line 84
Prefer .filter_map() over .filter().map() when the two operations can be combined.
- Very specific: line 85
Use .fold() for accumulation rather than a mutable variable outside the loop.
- Very specific: line 91
Modules and visibility: Use mod + pub to encapsulate logic.
- Very specific: line 93
Enums over flags: Prefer enum variants over bool parameters or integer flags.
- Distinctive: line 95
Builders for complex construction: Use the builder pattern when a struct has more than 3–4 optional fields.
- Very specific: line 101
Data parallelism: Use rayon for CPU-bound parallel iteration.
- Very specific: line 102
Binary/library split: Keep main.rs thin — move all logic into lib.rs and its modules.
- Very specific: line 148
Newtypes: Use newtypes to distinguish values that share the same primitive type (struct UserId(u64) vs struct OrderId(u64)).
- Distinctive: line 152
Sealed traits: Use the sealed trait pattern to prevent downstream implementations of traits not intended for extension.
- Very specific: line 155
Deref/DerefMut: Only smart pointers should implement these. - Very specific: line 157
Argument types: Prefer specific types over generic bool parameters.
- Very specific: line 164
Use tokio as the async runtime.
- Very specific: line 165
Never call .block_on() inside an async context.
- Very specific: line 166
Use tokio::spawn for background tasks.
- Very specific: line 167
Prefer tokio::fs over std::fs in async code.
- Very specific: line 168
Keep async boundaries at the edges — pure computation should be synchronous.
- Very specific: line 174
Run rustfmt (taskit check fmt) before every commit.
- Very specific: line 175
Run taskit check lint and fix all warnings.
- Distinctive: line 176
Keep lines at or under 100 characters.
- Very specific: line 177
Place doc comments (///) immediately above the item they document.
- Very specific: line 178
Use //! for module-level documentation.
- Distinctive: line 179
Document error conditions, panic scenarios, and safety considerations.
- Very specific: line 185
Write unit tests in #[cfg(test)] modules in the same file as the code under test.
- Very specific: line 186
Write integration tests in tests/ with descriptive file names.
- Very specific: line 187
Use taskit test run (preferred over taskit test run) for test filtering and parallelism.
- Distinctive: line 188
Test edge cases explicitly — not just the happy path.
- Very specific: line 211
Use semantic versioning in Cargo.toml.
- Distinctive: line 213
Use feature flags for optional functionality.
- Very specific: line 214
Keep main.rs and lib.rs minimal — move logic to named modules.
- Distinctive: line 222
Before submitting any Rust code:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust Conventions
Apply these rules to all Rust code written in this workspace. Prioritise readability, safety, and maintainability in that order.
Naming (RFC 430)
Follow RFC 430 naming conventions throughout:
| Item | Convention | Example |
| Types, traits, enums | UpperCamelCase | TaskGraph, PolicyAction |
| Functions, methods, variables | snake_case | check_tool, max_calls |
| Constants, statics | SCREAMING_SNAKE_CASE | MAX_NODES, DEFAULT_TIMEOUT |
| Modules | snake_case | mod graph_store |
| Lifetimes | short lowercase | 'a, 'src |
| Type parameters | short UpperCamelCase | T, E, Fut |
Ownership and Borrowing
- Prefer
&Tover cloning unless ownership transfer is required. - Use
&mut Twhen you need to mutate borrowed data. - Annotate lifetimes explicitly when the compiler cannot infer them.
Rc<T>for single-threaded reference counting;Arc<T>for multi-threaded.RefCell<T>for interior mutability in single-threaded contexts;Mutex<T>orRwLock<T>for multi-threaded.- Prefer borrowing and zero-copy operations to avoid unnecessary allocations.
- Use
&strinstead ofStringfor function parameters when ownership is not required.
Error Handling
- Use
Result<T, E>for all recoverable errors. Neverunwrap()orexpect()in library code — returnResultinstead. - Use the
?operator for error propagation. Avoidunwrap()unless in a test or a context where panic is explicitly acceptable. - Create custom error types with
thiserror; useanyhowfor application-level error aggregation. - Use
Option<T>for values that may legitimately be absent. - Provide meaningful error messages with context. Error types must implement
DebugandDisplayat minimum. - Validate function arguments and return appropriate errors for invalid input.
panic!is only for unrecoverable programmer errors (broken invariants). Never panic in response to external input.
// Prefer
fn load(path: &str) -> anyhow::Result<Config> {
let text = std::fs::read_to_string(path)?;
Ok(serde_json::from_str(&text)?)
}
// Avoid
fn load(path: &str) -> Config {
let text = std::fs::read_to_string(path).unwrap(); // panics on missing file
serde_json::from_str(&text).unwrap()
}Iterators and Collections
- Use iterators instead of index-based loops — they are often faster, safer, and more expressive.
- Avoid premature
.collect()— keep iterator chains lazy until a collection is actually needed. - Prefer
.filter_map()over.filter().map()when the two operations can be combined. - Use
.fold()for accumulation rather than a mutable variable outside the loop.
Patterns to Follow
- Modules and visibility: Use
mod+pubto encapsulate logic. Keep internal types private; expose only what callers need. - Enums over flags: Prefer enum variants over
boolparameters or integer flags. Type safety catches misuse at compile time. - Builders for complex construction: Use the builder pattern when a struct has more than 3–4 optional fields.
- Trait abstraction: Implement traits to abstract services and external dependencies, making them replaceable in tests.
- Async: Structure async code with
async/awaitandtokio. Avoid blocking in async contexts. - Data parallelism: Use
rayonfor CPU-bound parallel iteration. - Binary/library split: Keep
main.rsthin — move all logic intolib.rsand its modules. This enables integration tests and downstream crate reuse.
Patterns to Avoid
unwrap()/expect()in non-test, non-prototype code.- Panics in library code.
- Global mutable state — use dependency injection or thread-safe containers.
- Deeply nested
if/matchblocks — extract functions or use combinators. - Ignoring compiler warnings — treat
-D warningsas the standard in CI. unsafewithout necessity and thorough documentation.- Overusing
.clone()where a borrow would suffice. - Unnecessary heap allocations in hot paths.
Common Traits
Eagerly derive or implement these where appropriate:
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MyType { ... }| Trait | When |
Debug | Every public type — required |
Clone | When callers need owned copies |
PartialEq, Eq | For value comparison and use in collections |
Hash | When used as a HashMap/HashSet key |
Default | When a zero-value construction is meaningful |
Display | For user-facing output |
From / Into | For idiomatic type conversions |
AsRef, AsMut | For generic borrowing interfaces |
FromIterator, Extend | For collection types |
Send and Sync are auto-implemented by the compiler. Avoid manual unsafe impl Send/Sync
unless you fully understand the invariants.
API Design
- Newtypes: Use newtypes to distinguish values that share the same primitive type
(
struct UserId(u64)vsstruct OrderId(u64)). - Private fields: Structs should have private fields by default. Expose state through methods to preserve invariants.
- Sealed traits: Use the sealed trait pattern to prevent downstream implementations of traits not intended for extension.
- Method receivers: Functions with a clear receiver should be methods, not free functions.
Deref/DerefMut: Only smart pointers should implement these. Do not implementDerefto gain method inheritance.- Argument types: Prefer specific types over generic
boolparameters. Aboolargument at a call site conveys no intent (create(true)vscreate(CreateMode::Overwrite)).
Async
- Use
tokioas the async runtime. Do not mix runtimes. - Never call
.block_on()inside an async context. - Use
tokio::spawnfor background tasks; propagateJoinHandleerrors. - Prefer
tokio::fsoverstd::fsin async code. - Keep
asyncboundaries at the edges — pure computation should be synchronous.
Code Style
- Run
rustfmt(taskit check fmt) before every commit. - Run
taskit check lintand fix all warnings. - Keep lines at or under 100 characters.
- Place doc comments (
///) immediately above the item they document. - Use
//!for module-level documentation. - Document error conditions, panic scenarios, and safety considerations.
Testing
- Write unit tests in
#[cfg(test)]modules in the same file as the code under test. - Write integration tests in
tests/with descriptive file names. - Use
taskit test run(preferred overtaskit test run) for test filtering and parallelism. - Test edge cases explicitly — not just the happy path.
- Examples in doc comments must compile and use
?, notunwrap().
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_tool_denies_blocked() {
let policy = GovernancePolicy {
blocked_tools: vec!["shell_exec".into()],
..Default::default()
};
assert_eq!(policy.check_tool("shell_exec"), PolicyAction::Deny);
}
}Project Organisation
- Use semantic versioning in
Cargo.toml. - Include
description,license,repository,keywords,categoriesin every crate. - Use feature flags for optional functionality.
- Keep
main.rsandlib.rsminimal — move logic to named modules. - Organise modules as
mod.rsdirectory layout (src/foo/mod.rs) rather than flat files (src/foo.rs). This is the preferred convention in this workspace.
Quality Checklist
Before submitting any Rust code:
- Naming follows RFC 430 throughout
- All public types derive or implement
Debug - Error handling uses
Result<T, E>— no bareunwrap()in non-test code - All public items have
///rustdoc with at least one sentence - Tests cover the happy path and at least one failure/edge case
- No
unsafewithout a// SAFETY:comment explaining the invariant taskit check fmt— no format difftaskit check lint— zero warningstaskit test run— all green
Related
skills/agent-governance/SKILL.md— Rust implementations of governance patternsskills/systematic-debugging/SKILL.md— debugging approach for Rust-specific issuesskills/verification-before-completion/SKILL.md— CI gate checklist
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

