/predicate:rustfrom predicate
Guides idiomatic Rust development with conventions for API design, error handling, and type system usage. Activates when working with .rs files or Rust tooling.
Ships in predicate. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Work with the language, not against it. Embrace ownership, the borrow checker, and the type system.
unsafe unless absolutely necessary.| Prefix | Semantics | Cost | Example |
|---|---|---|---|
as_ | Borrowed view, no allocation | Cheap | as_ref(), as_slice() |
to_ | Creates new owned value | Expensive | to_string(), to_vec() |
into_ | Consumes self, transforms | Cheap | into_iter(), into_inner() |
Accept generic bounds instead of concrete types:
// ❌ Inflexible
fn read_file(path: &PathBuf) -> Result<String>
// ✅ Accepts &str, String, PathBuf, &Path
fn read_file(path: impl AsRef<Path>) -> Result<String>
Common patterns:
impl AsRef<Path> — for pathsimpl AsRef<str> — for string-like typesimpl Into<String> — when ownership is neededT::new() for basic instantiationT::with_capacity(n) for single-option variantslet config = ConfigBuilder::new()
.port(8080)
.timeout(Duration::from_secs(30))
.build()?;
For widely-used generic functions, consider splitting:
// Public generic wrapper (thin)
pub fn process(path: impl AsRef<Path>) -> Result<()> {
process_inner(path.as_ref())
}
// Private concrete implementation (bulk of logic)
fn process_inner(path: &Path) -> Result<()> {
// ...
}
This reduces binary bloat and compile times.
? OperatorUse ? to propagate errors. It:
Ok(value) or returns Err(e) earlyFrom trait| Context | Approach | Crate |
|---|---|---|
| Libraries | Custom enum error types | thiserror |
| Applications | Boxed errors with context | anyhow |
// Library: structured, matchable errors
#[derive(Debug, thiserror::Error)]
pub enum ParseError {
#[error("invalid header at byte {0}")]
InvalidHeader(usize),
#[error("unexpected EOF")]
UnexpectedEof,
}
// Application: rich context chains
fn main() -> anyhow::Result<()> {
let config = load_config()
.context("failed to load configuration")?;
Ok(())
}
Encode invariants in the type system:
// ❌ Stringly-typed, requires repeated validation
fn send_email(to: &str) -> Result<()>
// ✅ Invalid states are unrepresentable
fn send_email(to: EmailAddress) -> Result<()>
The constructor for EmailAddress validates once; all downstream code operates with a compile-time guarantee.
Iterators are lazy and zero-cost. Build declarative pipelines:
let result: Vec<_> = items
.iter()
.filter(|x| x.is_valid())
.map(|x| x.transform())
.collect();
| Adapter | Purpose |
|---|---|
map | Transform each element |
filter | Keep elements matching predicate |
filter_map | Filter and transform in one step |
flat_map | Map then flatten nested iterators |
zip | Combine two iterators into pairs |
chain | Concatenate iterators |
take / skip | Limit or offset elements |
inspect | Debug: observe without modifying |
collect, sum, for_each)map; use for_each or explicit loopsinspect() to debug intermediate pipeline stages| Trait | Meaning |
|---|---|
Send | Ownership can transfer between threads |
Sync | References (&T) can be shared between threads |
Most types are automatically Send + Sync. Types containing raw pointers or interior mutability may not be.
Mutex<T> — mutual exclusionRwLock<T> — multiple readers OR single writerArc<T> — atomic reference counting for shared ownershipmpsc::channel — message passingif let Deadlock (pre-2024 edition)// ❌ Lock held through else block in older editions
if let Some(x) = mutex.lock().unwrap().get("key") {
// ...
} else {
mutex.lock().unwrap().insert("key", value); // DEADLOCK
}
// ✅ Extract lock explicitly
let guard = mutex.lock().unwrap();
let result = guard.get("key").cloned();
drop(guard); // Release before else
Fixed in Rust 2024 edition.
Wrap primitives to create distinct types:
struct UserId(u64);
struct PostId(u64);
// Now UserId and PostId are incompatible at compile time
#[must_use]Apply to functions/types where ignoring the result is almost always a bug:
#[must_use = "this returns a new value and does not modify self"]
fn sorted(&self) -> Vec<T>
impl Trait in Return PositionHide concrete types when they're implementation details:
fn make_iter() -> impl Iterator<Item = u32> {
(0..10).filter(|x| x % 2 == 0)
}
| Anti-Pattern | Description | Remedy |
|---|---|---|
| Overengineering | Complex abstractions, premature unsafe, macro abuse | Prefer simple, direct solutions |
| Simplistic Design | Failing to leverage type system (stringly-typed, bool-blind) | Use enums/newtypes to encode invariants |
| Premature Optimization | Optimizing without profiling | Write clear code first; measure, then optimize |
| Documentation Neglect | Missing or stale docs | Doc-comments (///) with examples; run cargo doc |
| Domain | Crate | Notes |
|---|---|---|
| Serialization | serde + serde_json | De facto standard |
| Async Runtime | tokio | Most widely supported |
| CLI Parsing | clap | Feature-rich, fast |
| Error (Library) | thiserror | Derive for custom errors |
| Error (Application) | anyhow | Context chains, backtraces |
| HTTP Client | reqwest | Built on tokio |
| Logging | tracing | Structured, async-aware |
.unwrap() in library code — propagate Result.clone() without justification — prefer referencespanic! in library code — return errorsclippy — cargo clippy -- -D warningsrustfmt — cargo fmt/// with examplesThese idioms refine but are subordinate to the Code-Edit Constraints.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub nrdxp/predicate --plugin predicate35 skills in this plugin
/ai-auditSOP for auditing AI-generated code.
Trigger when:
- Reviewing, refactoring, or cleaning up AI-generated code to prevent regressions or hallucinated APIs.
- Prompt contains: /ai-audit, code audit, AI cleanup, common flaws.
/api-auditProtocol for auditing API surface coherence and type safety.
Trigger when:
- Evaluating API designs, interface type safety, or design elegance.
- Prompt contains: /api-audit, API surface, API coherence, type safety.
/boundaryNormative sufficiency conditions for Initial Boundary Conditions (IBCs)
and the SOP for the cheap-tier boundary refinement loop (/boundary).
Trigger when:
- Crafting, auditing, or refining a prompt/IBC destined for an expensive
(architect-class) model or an autonomous worker dispatch.
- Evaluating whether a task frame is sufficient to bound an agent walk.
- Prompt contains: /boundary, IBC, initial boundary condition, boundary
contract, sufficiency conditions, worker prompt, prompt refinement.
Other plugins' skills for the same job