Rust Development
This skill enforces new code or code changes to conform to proper Rust guidelines.
When to Use
Activate this skill when:
- Writing new Rust code
- Reviewing or modifying existing Rust code
- Designing Rust APIs, libraries, or applications
- Refactoring Rust codebases
Required Gates (Before Submitting Code)
All code must pass these checks:
cargo +nightly fmt # format
cargo clippy -- -D warnings # lint with no warnings
cargo test # tests pass
cargo doc --no-deps # docs build
Code that fails clippy or is not properly formatted should not be committed. See project-and-tooling.md for required lints and rustfmt.toml config.
Reference Files
Load the relevant file when working on the matching topic:
| Topic |
File |
Naming conventions (RFC 430), case rules, conversion methods (as_/to_/into_), getter/iterator method conventions |
naming.md |
Type safety (newtypes, primitive obsession, bitflags, builders) and trait implementations (Clone, Debug, From/TryFrom, Deref rules, object safety, Serde behind feature flags) |
types.md |
Error type requirements, thiserror for libraries, anyhow for applications, propagating with ?, let ... else for early returns |
error-handling.md |
Public-item docs, # Arguments/# Errors/# Panics/# Safety/# Examples sections, #[doc(hidden)] for implementation details |
documentation.md |
Minimizing unsafe, thread safety, Drop must not fail, avoiding allocations, iterators over indexing, &str over String, Cow |
safety-and-performance.md |
| API design (no out-parameters, intermediate results, constructors as static methods, generics over concrete types, input validation) and forward compatibility (private fields, sealed traits) |
api-design.md |
Cargo.toml metadata, module organization, feature flags, test organization, property-based testing, required clippy lints, rustfmt.toml, pre-commit checks |
project-and-tooling.md |
Guidelines Sources
These guidelines are based on:
Code Review Checklist
Required
Naming (naming.md)
Types (types.md)
Safety (safety-and-performance.md)
Documentation (documentation.md)
Performance (safety-and-performance.md)
Testing (project-and-tooling.md)
1---2name: rust-development3description: Expert Rust development guidance covering naming conventions, type safety, error handling, documentation, and best practices based on official Rust guidelines. Use this skill when writing new Rust code, reviewing or modifying existing Rust code, designing Rust APIs or libraries, refactoring Rust codebases, or whenever the user mentions Rust, Cargo, clippy, rustfmt, traits, lifetimes, or `.rs` files.4license: Apache-2.05---67# Rust Development89This skill enforces new code or code changes to conform to proper Rust guidelines.1011## When to Use1213Activate this skill when:14- Writing new Rust code15- Reviewing or modifying existing Rust code16- Designing Rust APIs, libraries, or applications17- Refactoring Rust codebases1819## Required Gates (Before Submitting Code)2021All code must pass these checks:2223```bash24cargo +nightly fmt # format25cargo clippy -- -D warnings # lint with no warnings26cargo test # tests pass27cargo doc --no-deps # docs build28```2930Code that fails clippy or is not properly formatted should not be committed. See [project-and-tooling.md](project-and-tooling.md) for required lints and `rustfmt.toml` config.3132## Reference Files3334Load the relevant file when working on the matching topic:3536| Topic | File |37|-------|------|38| Naming conventions (RFC 430), case rules, conversion methods (`as_`/`to_`/`into_`), getter/iterator method conventions | [naming.md](naming.md) |39| Type safety (newtypes, primitive obsession, bitflags, builders) and trait implementations (`Clone`, `Debug`, `From`/`TryFrom`, `Deref` rules, object safety, Serde behind feature flags) | [types.md](types.md) |40| Error type requirements, `thiserror` for libraries, `anyhow` for applications, propagating with `?`, `let ... else` for early returns | [error-handling.md](error-handling.md) |41| Public-item docs, `# Arguments`/`# Errors`/`# Panics`/`# Safety`/`# Examples` sections, `#[doc(hidden)]` for implementation details | [documentation.md](documentation.md) |42| Minimizing `unsafe`, thread safety, `Drop` must not fail, avoiding allocations, iterators over indexing, `&str` over `String`, `Cow` | [safety-and-performance.md](safety-and-performance.md) |43| API design (no out-parameters, intermediate results, constructors as static methods, generics over concrete types, input validation) and forward compatibility (private fields, sealed traits) | [api-design.md](api-design.md) |44| `Cargo.toml` metadata, module organization, feature flags, test organization, property-based testing, required clippy lints, `rustfmt.toml`, pre-commit checks | [project-and-tooling.md](project-and-tooling.md) |4546## Guidelines Sources4748These guidelines are based on:49- [Microsoft Rust Guidelines](https://microsoft.github.io/rust-guidelines/)50- [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/)51- [The Rust Programming Language Book](https://doc.rust-lang.org/book/)52- Rust community best practices5354## Code Review Checklist5556### Required57- [ ] Code passes `cargo clippy -- -D warnings`58- [ ] Code is formatted with `cargo +nightly fmt`59- [ ] Tests pass with `cargo test`6061### Naming ([naming.md](naming.md))62- [ ] Follows RFC 430 case conventions63- [ ] Conversions use `as_`/`to_`/`into_` correctly64- [ ] No `get_` prefix on simple getters65- [ ] Iterator methods follow conventions6667### Types ([types.md](types.md))68- [ ] Uses newtypes for distinct concepts69- [ ] Avoids bool/Option parameters with unclear meaning70- [ ] Implements appropriate standard traits71- [ ] Error types implement `Error + Send + Sync`7273### Safety ([safety-and-performance.md](safety-and-performance.md))74- [ ] Minimizes `unsafe` code75- [ ] Documents safety invariants76- [ ] Validates inputs at boundaries7778### Documentation ([documentation.md](documentation.md))79- [ ] All public items documented80- [ ] Examples compile and demonstrate usage81- [ ] Error/panic conditions documented8283### Performance ([safety-and-performance.md](safety-and-performance.md))84- [ ] Avoids unnecessary allocations85- [ ] Uses iterators appropriately86- [ ] Takes references where ownership isn't needed8788### Testing ([project-and-tooling.md](project-and-tooling.md))89- [ ] Unit tests for core logic90- [ ] Integration tests for public API91- [ ] Edge cases covered