agentleFS
DankosikDankosik/cargo-modernize/.agents/skills/rust-idiomatic/SKILL.md

rust-idiomatic

Skill0 starsChanged 5 days agoApache-2.0View on GitHub

Contracts. Use when designing a Rust type, signature, trait impl, conversion, or resolving clone, Arc, Mutex, or borrow ownership.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Rust Idiomatic

Contracts. Make ownership and caller expectations visible in ordinary Rust: admissible states, permitted transitions, mutation authority, and the meaning of absence or failure. Remember that a type enforces only its construction and transition invariants; freshness, durable completion, and external resource lifetimes require explicit runtime coordination.

Sharing and parameters. Inspect scope and data flow before choosing a clone or shared owner. Use a deliberate .clone() or Arc when required sharing or simpler ownership fits within cost bounds; prefer owned struct fields unless a borrowed view earns its container lifetimes, and keep concrete parameter types in application code unless actual callers benefit from generic conversions.

Mutation and completion. Prefer &mut exclusive mutation; pair interior mutability or Arc sharing with an explicit invariant and synchronization protocol. Require Send, Sync, and 'static bounds only at real task or thread crossings. Borrow retained state in place for inspection or update, reserving mem::take or mem::replace for true ownership transfer whose replacement state remains valid on every exit; see the ownership example. Prefer a scoped guard (std::mem::DropGuard or an existing handle wrapper) for one-off infallible cleanup, use RAII for unwinding release, and expose an explicit observed completion step whenever flushing or closing can fail or suspend.

Representation. Keep independently varying facts independent and bind any justified derived projection or cache to its source owner in the type, as shown in the representation example, decoding external sentinel conventions at their boundary. Separate absent from empty only when the contract distinguishes them, prefer named fields outside narrow local scope, wrap distinct units or identifiers in newtypes so the compiler prevents interchange, and replace ambiguous boolean parameters while keeping independent boolean flags simple.

Boundary invariants. Parse and validate at the owning boundary, then carry checked values inward. Audit every construction and mutation path—Deserialize, From/TryFrom, Default, and field visibility—so invariant-bearing fields stay private while plain data stays direct. Reserve builders for multi-option or staged construction and typestate for APIs whose compile-time protocol outweighs its generic cost over an enum.

Traits and derivations. Implement From for lossless conversions, TryFrom for fallible ones, and explicit numeric cast methods where available; keep primary behavior in inherent methods and check whether consumers truly need dyn compatibility before constraining a trait. Derive standard traits where semantics match, implement Display for user-facing text and redacted Debug for secrets, keep Eq/Ord/Hash consistent, reserve Deref for smart pointers, and mark #[must_use] where ignoring a return value loses a required check or effect.

Collections and iterators. Select collections by access pattern and ordering (BTreeMap orders by key; IndexMap preserves insertion order), keep overflow and byte-versus-UTF-8 boundaries explicit, propagate fallible iterator results with collect::<Result<_, _>>(), and verify filter/take order, scoping changes strictly to touched code.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.