| name | policy-rust |
| description | Enforces Rust development policies including zero warnings, static dispatch preference, minimal Arc usage, and comprehensive testing requirements. Use when reviewing Rust code, writing new Rust code, or checking compliance with project policies. |
| metadata | {"author":"aiassisted","version":"1.0"} |
Rust Policy Enforcement
Enforces core Rust development policies for the aiassisted project. Use this skill to verify code compliance or guide implementation.
When to use this skill
Use this skill when:
- Writing new Rust code in this project
- Reviewing Rust code for policy compliance
- Checking if code meets project standards
- Fixing policy violations
Quick Reference
| Policy | Requirement |
|---|
| Zero warnings | cargo check must produce 0 warnings |
| Static dispatch | Prefer generics over dyn traits |
| Minimal Arc | Use Arc only for actual concurrent sharing |
| Testing | Unit tests for all modules (positive + negative) |
| Integration tests | Workflow tests in tests/ directory |
Policy Checklist
1. Zero Warning Policy
Verify no warnings:
cargo check 2>&1 | grep -c warning
Common fixes:
- Unused variable → prefix with
_ or remove
- Unused import → remove
- Dead code → remove or justify
#[allow(dead_code)]
2. Static Dispatch
Check for dynamic dispatch patterns:
fn process(handler: &dyn Handler) { }
fn process(handler: Box<dyn Handler>) { }
fn process<H: Handler>(handler: &H) { }
fn process(handler: impl Handler) { }
Acceptable exceptions:
- Heterogeneous collections
- Plugin systems
- Breaking dependency cycles
3. Minimal Arc Usage
Review Arc usage - this CLI runs sequentially with no shared state:
fn execute(fs: Arc<dyn FileSystem>) { }
fn execute<F: FileSystem>(fs: &F) { }
Arc is acceptable for:
- Actual multi-threaded sharing
- Async tasks across threads
4. Comprehensive Unit Tests
Every module must have:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_function_success() { }
#[test]
fn test_function_error() { }
#[test]
fn test_function_edge_case() { }
}
Required coverage:
- Success paths
- Error handling
- Edge cases (empty, large, Unicode)
- Boundary conditions
Mock dependencies with mockall:
use mockall::{mock, predicate::*};
mock! {
pub FileSystem {}
impl crate::core::infra::FileSystem for FileSystem {
async fn read(&self, path: &Path) -> Result<String>;
}
}
5. Integration Tests
Located in tests/ directory, use real implementations:
use wiremock::{Mock, MockServer, ResponseTemplate};
#[tokio::test]
async fn test_full_workflow() {
let mock_server = MockServer::start().await;
}
Review Workflow
-
Check warnings:
cargo check 2>&1 | grep warning
-
Search for dyn usage:
grep -r "dyn " src/
-
Search for Arc usage:
grep -r "Arc<" src/
-
Verify test coverage:
cargo test
-
Check for missing tests:
Look for modules without #[cfg(test)]
Detailed Reference
For comprehensive policy documentation, see rust-policy-guide.md.
Related Guidelines