Codex-skill-rust
Skill6 starsChanged 3 months agoMITView on GitHub
Guide for Rust development including code style, testing, building, and quality checks using cargo tools. Apply when working with Rust code, Cargo.toml, or running cargo commands.
- Installs packages
We split this skill into the rules it gives an agent
25 rules. About 0 are common, 12 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Follow standard Rust conventions and idioms
- Very specific: line 13
Use rustfmt for code formatting
- Distinctive: line 15
Prefer descriptive variable and function names
- Very specific: line 19
Prefer the modern <module_name>.rs style over the legacy mod.rs style for module files.
- Very specific: line 80
Use cfg_attr to deny lints only in release builds (not debug or test)
- Very specific: line 82
Document why each allow is necessary
- Very specific: line 88
Avoid .unwrap() and .expect() - these cause panics and should not be used in production code.
- Very specific: line 90
Use Result<T, E> return types with the ?
- Distinctive: line 91
Prefer early returns for error conditions
- Very specific: line 98
Libraries: Use thiserror to define custom error types with derive macros
- Very specific: line 99
Applications: Use anyhow for convenient error handling with context
- Very specific: line 143
Avoid println! and eprintln!
- Very specific: line 178
After use statements before the first item
- Distinctive: line 179
After code blocks (loops, conditionals, match arms) before subsequent statements
- Distinctive: line 183
When struct or enum fields have documentation comments, add a blank line before each doc comment to visually separate the fields:
- Distinctive: line 202
All items require rustdoc documentation comments.
- Distinctive: line 276
Write unit tests in the same file as the code being tested
- Very specific: line 277
Use integration tests in the tests/ directory for end-to-end functionality
- Very specific: line 278
Run tests with cargo test
- Distinctive: line 280
Document test functions with their purpose and what they verify
- Distinctive: line 284
After completing changes to Rust code, run the following checks in order:
- Distinctive: line 295
If any check fails, fix the issues before proceeding.
- Very specific: line 316
Always add dependencies with default-features = false and explicitly specify the features you need.
- Distinctive: line 326
When adding a new dependency:
- Distinctive: line 328
Check the crate's documentation for available features
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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 Development Guide
Code Style
- Follow standard Rust conventions and idioms
- Use
rustfmtfor code formatting - Configure lints in
lib.rs(see Crate-Level Lint Configuration below) - Prefer descriptive variable and function names
Module File Organization
Prefer the modern <module_name>.rs style over the legacy mod.rs style for module files.
Preferred (modern style):
src/
├── lib.rs
├── config.rs # mod config
├── config/
│ └── parser.rs # mod config::parser
├── network.rs # mod network
└── network/
├── client.rs # mod network::client
└── server.rs # mod network::serverAvoid (legacy style):
src/
├── lib.rs
├── config/
│ ├── mod.rs # mod config
│ └── parser.rs # mod config::parser
└── network/
├── mod.rs # mod network
├── client.rs # mod network::client
└── server.rs # mod network::serverBenefits of the modern style:
- File names directly indicate the module name (no ambiguous
mod.rsfiles) - Easier navigation in editors and file browsers
- Clear correspondence between module path and file path
- Supported since Rust 2018 edition
Crate-Level Lint Configuration
Define lint rules at the top of lib.rs (or main.rs for binaries) rather than via command-line flags. This ensures consistent enforcement and documents project standards.
#![deny(unsafe_code)]
#![cfg_attr(all(not(debug_assertions), not(test)), deny(clippy::all))]
#![cfg_attr(all(not(debug_assertions), not(test)), deny(clippy::pedantic))]
#![cfg_attr(all(not(debug_assertions), not(test)), deny(missing_docs))]
// Allow some pedantic lints that are too strict for this project
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::must_use_candidate)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::enum_variant_names)]
// Until 1.0.0, allow dead code and unused dependency warnings
#![allow(dead_code)]
#![allow(unused_crate_dependencies)]
Key principles:
- Deny
unsafe_codeunless explicitly required - Use
cfg_attrto deny lints only in release builds (not debug or test) - Allow specific pedantic lints that conflict with project conventions
- Document why each
allowis necessary
Important: These are good defaults for new crates. Do not override existing lint configurations - if a crate already specifies deny or allow for a rule, respect that choice.
Error Handling
Avoid .unwrap() and .expect() - these cause panics and should not be used in production code. Instead:
- Use
Result<T, E>return types with the?operator for error propagation - Prefer early returns for error conditions
- Handle errors explicitly at appropriate boundaries
Error Type Crates
Note: The following recommendations apply to std crates only. For no_std embedded targets, use custom error enums or thiserror with default-features = false.
- Libraries: Use
thiserrorto define custom error types with derive macros - Applications: Use
anyhowfor convenient error handling with context
Example library error type with thiserror:
use thiserror::Error;
/// Errors that can occur during data processing.
#[derive(Debug, Error)]
pub enum ProcessError {
/// The input data was empty.
#[error("input data cannot be empty")]
EmptyInput,
/// Failed to parse the input data.
#[error("failed to parse input: {0}")]
ParseFailure(String),
/// An I/O error occurred.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}Example application error handling with anyhow:
use anyhow::{Context, Result};
fn load_config(path: &Path) -> Result<Config> {
let contents = std::fs::read_to_string(path)
.context("failed to read config file")?;
let config: Config = serde_json::from_str(&contents)
.context("failed to parse config JSON")?;
Ok(config)
}Logging
Note: The following recommendations apply to std crates only. For no_std embedded targets, use defmt or platform-specific logging mechanisms.
Avoid println! and eprintln! outside of main application entry points. Use the log crate for structured logging instead.
use log::{debug, info, warn, error};
fn process_data(data: &[u8]) -> Result<(), ProcessError> {
debug!("Processing {} bytes", data.len());
if data.is_empty() {
warn!("Received empty data buffer");
return Err(ProcessError::EmptyInput);
}
info!("Data processed successfully");
Ok(())
}Log levels:
error!- Unrecoverable errors or failureswarn!- Unexpected conditions that are handledinfo!- Significant events in normal operationdebug!- Detailed information for debuggingtrace!- Very detailed tracing information
Applications should initialise a log implementation (e.g., env_logger, tracing-subscriber) in main().
Whitespace and Formatting
Maintain blank lines for readability:
- Between module-level items (functions, structs, enums, traits, constants, impl blocks)
- Between struct and enum members when they have doc comments
- Between constant declarations
- After
usestatements before the first item - After code blocks (loops, conditionals, match arms) before subsequent statements
Struct Field Formatting
When struct or enum fields have documentation comments, add a blank line before each doc comment to visually separate the fields:
pub struct Handle<T> {
/// Index into the arena's resource vector.
index: usize,
/// Generation counter to detect stale handles after resource reuse.
generation: u32,
/// Type marker to prevent mixing handles of different resource types.
_marker: PhantomData<T>,
}For fields without documentation, blank lines are optional but may still aid readability for complex types.
Documentation
All items require rustdoc documentation comments.
For documenting the following item (functions, types, constants, fields):
/// Documentation for the item below.For documenting the enclosing item (modules, crate root):
//! Documentation for the containing module.Items requiring documentation include:
- Functions and methods
- Types (structs, enums, type aliases)
- Traits and trait implementations
- Constants and statics
- Modules
- Test functions
- Struct and enum fields
Function Documentation
Function documentation must include:
- Brief description of purpose
# Argumentssection documenting each parameter# Returnssection documenting the return value# Errorssection if the function returnsResult# Panicssection if the function can panic
Example:
/// Calculates the checksum for the given data buffer.
///
/// # Arguments
///
/// * `data` - The byte slice to calculate the checksum for.
/// * `seed` - Initial seed value for the checksum algorithm.
///
/// # Returns
///
/// The computed 32-bit checksum value.
///
/// # Errors
///
/// Returns `ChecksumError::EmptyBuffer` if `data` is empty.
fn calculate_checksum(data: &[u8], seed: u32) -> Result<u32, ChecksumError> {
// ...
}Constant Documentation
Constant documentation must include:
- Description of the constant's purpose
- Reference to specification, document, or section where applicable
Example:
/// Maximum transmission unit size in bytes.
///
/// Per RFC 894, Section 3 - Ethernet frames have a maximum payload of 1500 bytes.
const MTU_SIZE: usize = 1500;Testing
- Write unit tests in the same file as the code being tested
- Use integration tests in the
tests/directory for end-to-end functionality - Run tests with
cargo test - Aim for meaningful test coverage of core functionality
- Document test functions with their purpose and what they verify
Build Verification
After completing changes to Rust code, run the following checks in order:
- Format Code:
cargo fmt - Format Check:
cargo fmt --check - Lint Check:
cargo clippy -- -D warnings - Tests:
cargo test - Release Build:
cargo build --release - Documentation:
cargo doc --no-deps --document-private-items - License Check:
cargo deny check - Security Audit:
cargo audit
If any check fails, fix the issues before proceeding.
Security Tools
Projects should use these security tools:
- cargo-deny: License and advisory checker. Install with
cargo install cargo-deny. Configuration indeny.tomlenforces permissive licenses (MIT, Apache-2.0, BSD) and denies copyleft licenses (GPL, LGPL, AGPL). - cargo-audit: Security vulnerability scanner. Install with
cargo install cargo-audit. Scans dependencies against the RustSec Advisory Database.
Dependencies
When adding dependencies:
- Choose well-maintained crates widely used in the Rust ecosystem
- For workspaces, add shared dependencies to
[workspace.dependencies]in rootCargo.toml - Justify each dependency with a clear use case
- Disable default features and explicitly enable only required features
Minimising Dependencies
Always add dependencies with default-features = false and explicitly specify the features you need. This reduces compile times and binary size by avoiding unnecessary transitive dependencies.
# Prefer this:
serde = { version = "1.0", default-features = false, features = ["derive"] }
# Avoid this:
serde = "1.0"When adding a new dependency:
- Check the crate's documentation for available features
- Identify the minimum set of features required for your use case
- Add with
default-features = false - Explicitly list only the features you need
In this repository346 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/skills/deeppapernote/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .claude/skills/deeppapernote/CLAUDE.mdCLAUDE.md
- docs/llms-full.txtllms.txt
- docs/llms.txtllms.txt
- llms.txtllms.txt
- academic-cv-builderSkill
- agenticx-a2a-connectorSkill
- agenticx-agent-builderSkill
- agenticx-automation-crontaskSkill
- agenticx-deployerSkill
- agenticx-memory-architectSkill
- agenticx-quickstartSkill
- agenticx-skill-managerSkill
- agenticx-tool-creatorSkill
- agenticx-workflow-designerSkill
- ai-slop-detectorSkill
- alert-managerSkill
- algorithmic-artSkill
- api-gatewaySkill
- backlink-analyzerSkill
- brand-guidelinesSkill
- canvas-designSkill
- career-changer-translatorSkill
- Codex-apiSkill
- claw-releaseSkill
- clawsec-clawhub-checkerSkill
- clawsec-feedSkill
- clawsec-nanoclawSkill
- clawsec-scannerSkill
- clawsec-suiteSkill
- clawtributorSkill
- cn-statsSkill
- codebase-documenterSkill
- code-dev-workflowSkill
- competitor-analysisSkill
- content-experimentation-best-practicesSkill
- content-gap-analysisSkill
- content-modeling-best-practicesSkill
- content-quality-auditorSkill
- content-refresherSkill
- context-mode-opsSkill
- context-modeSkill
- cover-letter-generatorSkill
- creative-portfolio-resumeSkill
- crypto-reportSkill
- ctx-doctorSkill
- ctx-insightSkill
- ctx-purgeSkill
- ctx-statsSkill
- ctx-upgradeSkill
- deep-cleanSkill
- doc-coauthoringSkill
- docxSkill
- domain-authority-auditorSkill
- edgeoneSkill
- edge-ttsSkill
- entity-optimizerSkill
- executive-resume-writerSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

