templates/skills/languages/rust/SKILL.md
Execute these commands after EVERY implementation (see AGENT_AUTOMATION module for full workflow).
npx skillsauth add hivellm/rulebook RustInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
CRITICAL: Execute these commands after EVERY implementation (see AGENT_AUTOMATION module for full workflow).
# Complete quality check sequence:
cargo fmt --all -- --check # Format check
cargo clippy --workspace --all-targets --all-features -- -D warnings # Lint
cargo test --workspace --all-features # All tests (100% pass)
cargo build --release # Build verification
cargo llvm-cov --all # Coverage (95%+ required)
# Security audit:
cargo audit # Vulnerability scan
cargo outdated # Check outdated deps
CRITICAL: Always use Rust Edition 2024 with nightly toolchain.
rustup update nightly regularlyrustfmt with nightly toolchainrustfmt.toml or .rustfmt.tomlcargo +nightly fmt --allcargo +nightly fmt --all -- --checkclippy with -D warnings (warnings as errors)#[allow(clippy::...)] and justificationcargo clippy --workspace -- -D warnings/tests directory for integration tests#[cfg(test)]cargo-nextest for faster test executiontokio::test for async tests with Tokio runtimeExample test structure:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_feature() {
// Test implementation
}
#[tokio::test]
async fn test_async_feature() {
// Async test implementation
}
}
CRITICAL: Tests must be categorized based on execution time and dependencies.
Tests that require active servers, databases, or external services must be isolated using Cargo features.
Implementation:
s2s feature in Cargo.toml:[features]
default = []
s2s = [] # Enable server-to-server tests
#[cfg(test)]
mod tests {
use super::*;
// Regular fast test (always runs)
#[test]
fn test_local_computation() {
// Fast test, no external dependencies
}
// S2S test (only runs with --features s2s)
#[cfg(feature = "s2s")]
#[tokio::test]
async fn test_database_connection() {
// Requires active database server
let db = connect_to_database().await?;
// ... test implementation
}
#[cfg(feature = "s2s")]
#[tokio::test]
async fn test_api_integration() {
// Requires active API server
let client = create_api_client().await?;
// ... test implementation
}
}
# Regular tests (excludes S2S)
cargo test
# Include S2S tests (requires active servers)
cargo test --features s2s
# CI/CD: Run S2S tests only when servers are available
cargo test --features s2s --test-args '--test-threads=1'
Tests that take > 10-20 seconds must be marked and run separately.
Implementation:
slow feature in Cargo.toml:[features]
default = []
slow = [] # Enable slow tests
#[cfg(test)]
mod tests {
use super::*;
// Fast test (always runs)
#[test]
fn test_quick_operation() {
// Completes in < 1 second
}
// Slow test (only runs with --features slow)
#[cfg(feature = "slow")]
#[test]
fn test_heavy_computation() {
// Takes 30+ seconds
// Heavy processing, large dataset, etc.
}
#[cfg(feature = "slow")]
#[tokio::test]
async fn test_large_file_processing() {
// Processes large files, takes > 20 seconds
}
}
# Regular tests (excludes slow)
cargo test
# Include slow tests
cargo test --features slow
# Run both S2S and slow tests
cargo test --features s2s,slow
tokio::time::timeout(Duration::from_secs(30), test_fn).await?CRITICAL: Follow Tokio best practices for async code.
spawn_blocking for CPU-intensive taskstokio::sync::mpsc or tokio::sync::broadcast for async communicationtokio::time::timeoutExample:
use tokio::time::{timeout, Duration};
async fn fetch_data() -> Result<Data, Error> {
timeout(Duration::from_secs(30), async {
// Network operation
}).await?
}
CRITICAL: Always verify latest versions before adding dependencies.
Check Context7 for latest version:
Example Workflow:
Adding tokio → Check crates.io and docs.rs
Adding serde → Verify latest version with security updates
Adding axum → Check for breaking changes in latest version
Document Version Choice:
Cargo.toml commentscargo auditCRITICAL: Use codespell to catch typos in code and documentation.
Install: pip install 'codespell[toml]'
Configuration in pyproject.toml:
[tool.codespell]
skip = "*.lock,*.json,target,node_modules,.git"
ignore-words-list = "crate,ser,deser"
Or run with flags:
codespell \
--skip="*.lock,*.json,target,node_modules,.git" \
--ignore-words-list="crate,ser,deser"
Result<T, E> for recoverable errorsthiserror for custom error typesanyhow for application-level error handlingunwrap() or expect() in production code without justificationExample:
use thiserror::Error;
#[derive(Error, Debug)]
pub enum MyError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid input: {0}")]
InvalidInput(String),
}
pub fn process_data(input: &str) -> Result<Data, MyError> {
// Implementation
}
///)//!unsafe codecargo test --docExample:
/// Processes the input data and returns a result.
///
/// # Arguments
///
/// * `input` - The input string to process
///
/// # Examples
///
/// ```
/// use mylib::process;
/// let result = process("hello");
/// assert_eq!(result, "HELLO");
/// ```
///
/// # Errors
///
/// Returns `MyError::InvalidInput` if input is empty.
pub fn process(input: &str) -> Result<String, MyError> {
// Implementation
}
project/
├── Cargo.toml # Package manifest
├── Cargo.lock # Dependency lock file (commit this)
├── README.md # Project overview (allowed in root)
├── CHANGELOG.md # Version history (allowed in root)
├── AGENTS.md # AI assistant rules (allowed in root)
├── LICENSE # Project license (allowed in root)
├── CONTRIBUTING.md # Contribution guidelines (allowed in root)
├── CODE_OF_CONDUCT.md # Code of conduct (allowed in root)
├── SECURITY.md # Security policy (allowed in root)
├── src/
│ ├── lib.rs # Library root (for libraries)
│ ├── main.rs # Binary root (for applications)
│ └── ...
├── tests/ # Integration tests
├── examples/ # Example code
├── benches/ # Benchmarks
└── docs/ # Project documentation
Must include GitHub Actions workflows for:
Testing (rust-test.yml):
cargo-nextest for fast test executionLinting (rust-lint.yml):
cargo +nightly fmt --all -- --checkcargo clippy --workspace -- -D warningscargo clippy --workspace --all-targets -- -D warningsCodespell (codespell.yml):
Prerequisites:
cargo loginCARGO_TOKEN to GitHub repository secretsCargo.toml Configuration:
[package]
name = "your-crate-name"
version = "1.0.0"
edition = "2024"
authors = ["Your Name <[email protected]>"]
license = "MIT OR Apache-2.0"
description = "A short description of your crate"
documentation = "https://docs.rs/your-crate-name"
homepage = "https://github.com/your-org/your-crate-name"
repository = "https://github.com/your-org/your-crate-name"
readme = "README.md"
keywords = ["your", "keywords", "here"]
categories = ["category"]
exclude = [
".github/",
"tests/",
"benches/",
"examples/",
"*.sh",
]
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Publishing Workflow:
cargo fmt --all
cargo clippy --workspace --all-targets -- -D warnings
cargo test --all-features
cargo doc --no-deps --all-features
git tag v1.0.0 && git push --tagscargo publishPublishing Checklist:
cargo test --all-features)cargo clippy -- -D warnings)cargo fmt --all -- --check)cargo doc --no-deps)cargo package --list)cargo publish --dry-runSemantic Versioning:
Follow SemVer strictly:
Documentation:
/// for public API documentation#![deny(missing_docs)] for librariescargo test --doc/// Processes the input data and returns a result.
///
/// # Arguments
///
/// * `input` - The input string to process
///
/// # Examples
///
/// ```
/// use your_crate::process;
///
/// let result = process("hello");
/// assert_eq!(result, "HELLO");
/// ```
///
/// # Errors
///
/// Returns an error if the input is empty.
pub fn process(input: &str) -> Result<String, Error> {
// Implementation
}
<!-- RUST:END -->research
Author a rulebook task spec interactively — research, draft, ask the user clarifying questions, confirm, then create the tasks in rulebook ready for /rulebook-driver. Use when the user wants to plan/spec a feature before implementing.
development
Behavioral guidelines to reduce common LLM coding mistakes — overcomplication, sloppy refactors, hidden assumptions, weak goals. Use when writing, reviewing, or refactoring code. Auto-applies; invoke explicitly via /karpathy-guidelines or 'follow karpathy discipline'.
data-ai
Autonomous AI agent loop for iterative task implementation (@hivehub/rulebook ralph)
data-ai
Use SQL Server for enterprise relational data storage with advanced features, high availability, and Windows integration.