rust

Enforce advanced Rust conventions beyond clippy and rustfmt on Cargo projects.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/dotBeeps/pantry --skill rust-dotbeeps
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust
Source: https://github.com/dotBeeps/pantry/tree/main/morsels/skills/rust
Command: npx skills add https://github.com/dotBeeps/pantry --skill rust-dotbeeps

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust projects often drift away from idiomatic patterns and robust practices beyond what cargo clippy and rustfmt enforce. This skill codifies advanced Rust conventions to improve readability, safety, and maintainability.

Core Features & Use Cases

  • Idioms: Prefer &str over &String in function parameters; use impl Trait in argument position for simple generics; prefer into()/from() over explicit constructors when a From impl exists; avoid overusing Rc/RefCell; use Cow<'_, str> to avoid allocations when possible; favor iterators and combinators over manual loops for readability.
  • Error Handling: Use Result<T, E> for recoverable errors; propagate errors with ?, and apply context; leverage thiserror for library errors and anyhow for application errors.
  • Ownership & Lifetimes: Structure data with ownership in mind; prefer owned types; minimize lifetimes; avoid long-lived references; use indices/keys for graph-like data.
  • Testing: Tests in #[cfg(test)] mod tests; integration tests in tests/; use #[should_panic] where appropriate; aim for expressive assertions.
  • Structure: One type per file when large; lib.rs as public API; module naming and privacy considerations.
  • Concurrency: Use message passing; prefer tokio async runtimes; avoid crossing await points with MutexGuard; use Arc when sharing across threads.

Quick Start

Ask the assistant to apply Rust conventions to a given Cargo project.

Frequently Asked Questions about rust

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

FAQPage Schema
What Rust conventions does clippy and rustfmt not cover?

Idiomatic Rust conventions beyond clippy and rustfmt include preferring &str over &String, leveraging into()/from() conversions, using Cow<'_, str> to avoid allocations, and favoring iterators over manual loops.

How do I structure Rust error handling with thiserror and anyhow?

Structure Rust error handling by using thiserror for library errors and anyhow for application errors. Propagate recoverable errors with Result<T, E> and the ? operator while applying appropriate context.

What's the best way to manage ownership and lifetimes in Rust projects?

Manage ownership and lifetimes by preferring owned types, minimizing lifetime annotations, avoiding long-lived references, and using indices or keys instead of references for graph-like data structures.

Can I apply these Rust code conventions to my existing Cargo project?

Yes, you can apply these Rust conventions to existing Cargo-based codebases during code review, refactoring, and learning tasks to enforce consistent patterns for readability, safety, and maintainability.

How do I avoid crossing await points with MutexGuard in async Rust?

Avoid crossing await points with MutexGuard in async Rust by using message passing and preferring tokio async runtimes. Use Arc when sharing data across threads to ensure safe concurrency.

When should I not use Rc and RefCell in Rust?

You should avoid overusing Rc and RefCell in Rust when standard ownership or Cow<'_, str> can prevent allocations. Prefer owned types and leverage iterators and combinators for better readability and safety.