rust-coding-patterns

Apply Rust coding patterns for ownership, concurrency, and error handling.

33|6|Updated Oct 9, 2025
One-click install
npx skills add https://github.com/CraftsMan-Labs/SimpleAgents --skill rust-coding-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-coding-patterns
Source: https://github.com/CraftsMan-Labs/SimpleAgents/tree/main/.opencode/skills/rust-coding-patterns
Command: npx skills add https://github.com/CraftsMan-Labs/SimpleAgents --skill rust-coding-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Rust projects frequently stumble over ownership pitfalls, unsafe concurrency, and inconsistent error handling across teams. This guide provides a structured set of patterns to drive idiomatic, safe, and maintainable Rust code during implementation, debugging, and reviews.

Core Features & Use Cases

  • Ownership and borrowing decisions: enforce clear ownership semantics, minimal borrows, and safe shared access.
  • Concurrency and error strategies: define bounded, cancellable async patterns and typed error handling to prevent panic-driven failures.
  • Type-driven design and invariants: use newtypes, typestate, and validated constructors to encode domain constraints.
  • Code review and refactor guidance: provide checklists and anti-pattern remediation to strengthen code quality across teams.

Quick Start

Choose a task mode (implement, debug, review, or refactor) and apply the corresponding Rust coding pattern guidelines to the codebase.

Frequently Asked Questions about rust-coding-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What are the best Rust design patterns for managing ownership and borrowing?

Rust ownership patterns enforce clear ownership semantics, minimal borrows, and safe shared access to prevent common borrow checker errors. Applying these guidelines ensures explicit ownership boundaries and type-driven invariants during implementation.

How do I handle async concurrency safely in Rust without causing panics?

Safe async concurrency in Rust relies on bounded, cancellable patterns and typed error handling strategies. This approach prevents panic-driven failures by defining strict concurrency boundaries and explicit error propagation.

How do I use typestate and newtypes to encode domain invariants in Rust?

Type-driven design in Rust uses newtypes, typestate patterns, and validated constructors to encode domain constraints directly into the type system. This method enforces type-driven invariants, making invalid states unrepresentable.

What should I look for when reviewing Rust code for anti-patterns?

Rust code reviews should check for explicit ownership boundaries, typed error strategies, and proper concurrency limits. Use structured checklists to identify anti-patterns and remediate unsafe code, ensuring maintainable and idiomatic implementations.

Does this Rust coding pattern guide apply to debugging and refactoring existing projects?

Yes, the Rust coding patterns apply directly to debugging, refactoring, and reviewing tasks across existing projects. The guidelines help remediate anti-patterns, enforce clear ownership semantics, and strengthen code quality during structural improvements.