rust-systems
Original:🇺🇸 English
Translated
Rust systems programming patterns and style guide for building reliable systems software. This skill should be used when writing Rust code, especially for systems programming, CLI tools, or performance-critical applications. Covers project organization with Cargo workspaces, module structure, naming conventions (RFC 430), type/trait patterns (Option, builders, associated types), and error handling with thiserror/anyhow.
4installs
Sourcepproenca/dot-skills
Added on
NPX Install
npx skill4agent add pproenca/dot-skills rust-systemsTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Rust Systems Programming Best Practices
Comprehensive Rust patterns and style conventions for systems programming, containing 52 rules across 5 categories. Designed for systems programming, CLI tools, and performance-critical applications.
When to Apply
Reference these guidelines when:
- Writing new Rust code or modules
- Organizing Rust project structure
- Defining custom types, traits, or error handling
- Reviewing Rust code for style consistency
- Building systems tools, CLIs, or daemon processes
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Project Organization | HIGH | |
| 2 | Module Structure | HIGH | |
| 3 | Naming Conventions | HIGH | |
| 4 | Type & Trait Patterns | HIGH | |
| 5 | Error Handling | HIGH | |
Quick Reference
1. Project Organization (HIGH)
- - Use Cargo Workspace for Multi-Crate Projects
org-cargo-workspace - - Use snake_case for All Directory Names
org-directory-naming - - Separate Binary and Library Crates
org-binary-library-separation - - Group Crates by Feature Domain
org-feature-domain-grouping - - Use Dedicated Common Crate for Shared Utilities
org-common-crate - - Keep Crate Structure Flat
org-flat-crate-structure
2. Module Structure (HIGH)
- - Use Explicit Module Declarations in lib.rs
mod-explicit-declarations - - Co-locate Tests as test.rs Files
mod-colocated-tests - - Use mod.rs for Multi-File Modules
mod-submodule-organization - - Separate Types and Errors into Dedicated Files
mod-types-errors-files - - Use pub use for Clean API Re-exports
mod-reexport-pattern - - Use cfg Attributes for Conditional Modules
mod-conditional-compilation
3. Naming Conventions (HIGH)
- - Use snake_case for Functions and Methods
name-function-snake-case - - Use PascalCase for Types
name-type-pascal-case - - Use SCREAMING_SNAKE_CASE for Constants
name-constant-screaming - - Prefix Getter Functions with get_
name-getter-prefix - - Use is_, has_, should_ for Boolean Predicates
name-boolean-predicates - - Use new for Constructors
name-constructor-new - - Use to_ and from_ for Conversions
name-conversion-to-from - - Use Descriptive Suffixes for Type Specialization
name-type-suffixes - - Include Unit Suffixes in Field Names
name-field-unit-suffixes - - Use snake_case for Module Names
name-module-snake-case - - Use Descriptive or Single-Letter Generic Parameters
name-generic-parameters - - Use Single Lowercase Letters for Lifetimes
name-lifetime-parameters - - Name Test Files as test.rs
name-test-files
4. Type & Trait Patterns (HIGH)
- - Use Option<T> for Nullable Fields
type-option-nullable-fields - - Use Consistent Derive Order for Data Structs
type-standard-derives - - Use Builder Pattern with Method Chaining
type-builder-pattern - - Use Associated Types for Related Type Relationships
type-associated-types - - Use PhantomData for Unused Generic Parameters
type-phantom-data - - Use Newtype Pattern for Type Safety
type-newtype-pattern - - Derive Copy for Simple Enums
type-enum-copy-simple - - Use Enums for Type-Safe Variants
type-enum-variants - - Group Related Trait Implementations Together
type-trait-impl-grouping - - Use bitflags! for Type-Safe Bit Flags
type-bitflags - - Implement Operator Traits for Domain Types
type-operator-overload - - Use Public Fields for Data Structs
type-public-fields - - Use async_trait for Async Trait Methods
type-async-trait - - Use Box<dyn Trait> for Runtime Polymorphism
type-boxed-trait-objects - - Use Type Aliases for Complex Generics
type-type-aliases
5. Error Handling (HIGH)
- - Use thiserror for Custom Error Types
err-thiserror-enum - - Define Module-Local Result Type Alias
err-result-alias - - Include Path Context in IO Errors
err-path-context - - Use context() and with_context() for Error Messages
err-anyhow-context - - Use bail! for Validation Failures
err-bail-validation - - Use Graceful Degradation for Non-Critical Operations
err-graceful-degradation - - Reserve panic! for Unrecoverable Situations
err-panic-unrecoverable - - Use expect() with Descriptive Messages
err-expect-message - - Use #[source] for Error Chaining
err-source-attribute - - Use ok_or_else for Expensive Error Construction
err-ok-or-else - - Use Two-Tier Error Strategy
err-two-tier-strategy
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md