rust

Applies idiomatic Rust conventions for writing, refactoring, and reviewing Rust code.

10|2|Updated Jan 24, 2026
One-click install
npx skills add https://github.com/nrdxp/predicate --skill rust-nrdxp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust
Source: https://github.com/nrdxp/predicate/tree/main/skills/rust
Command: npx skills add https://github.com/nrdxp/predicate --skill rust-nrdxp

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rust developers often fight the borrow checker, misuse error handling, or write unidiomatic code that ignores the type system. This Skill anchors AI-assisted Rust work to established idioms so generated code compiles cleanly, handles errors correctly, and follows community conventions. ## Core Features & Use Cases - API Design Guidance: Enforces naming conventions (as_/to_/into_), generic argument flexibility with impl AsRef<Path>, and Builder patterns for complex constructors. - Error Handling Patterns: Distinguishes library errors (thiserror custom enums) from application errors (anyhow context chains) and promotes parse-don't-validate type design. - Concurrency & Type System Rules: Covers Send/Sync semantics, Mutex/Arc primitives, newtypes, #[must_use], and deadlock pitfalls like the if let lock anti-pattern. - Use Case: When asking an agent to refactor a Rust module, it will propagate errors with ? instead of .unwrap(), accept impl AsRef<str> instead of concrete String, and run cargo clippy -- -D warnings before finishing. ## Quick Start Review this Rust file and refactor it to follow idiomatic error handling and API design conventions.

Frequently Asked Questions about rust

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

FAQPage Schema
How do I handle errors idiomatically in Rust?

Use the `?` operator to propagate errors, which unwraps Ok values or returns early with automatic From conversion. Libraries should define custom error enums with thiserror; applications should use anyhow for context-rich error chains.

What is the difference between thiserror and anyhow?

thiserror derives structured, matchable error enums for libraries where callers need to handle specific cases. anyhow provides boxed errors with context chains and backtraces for applications where errors mainly bubble up to the user.

When should I use impl AsRef<Path> instead of &PathBuf?

Use `impl AsRef<Path>` for function arguments so callers can pass &str, String, PathBuf, or &Path without conversion. The same pattern applies with `impl AsRef<str>` for string-like types and `impl Into<String>` when ownership is needed.

Why does my Rust code deadlock with if let and Mutex?

In editions before Rust 2024, a temporary lock guard in an `if let` condition stays alive through the else block, causing deadlock when the else tries to lock again. Extract the guard into a named variable and drop it explicitly before the else branch.

Should I use unwrap in Rust library code?

No. Library code should propagate errors with `?` and return Result instead of calling `.unwrap()` or `panic!`. Panics in libraries remove the caller's ability to recover; reserve unwrap for tests and examples.

What crates are recommended for common Rust tasks?

Use serde with serde_json for serialization, tokio for async runtime, clap for CLI parsing, reqwest for HTTP clients, and tracing for structured logging. For errors, use thiserror in libraries and anyhow in applications.