Skip to content
cccskills
FreePublished on GitHub

rust-best-practices

Rust best practices. Use when reading or editing any .rs file, designing a crate's public API, choosing an error type, splitting a workspace, or writing async code on tokio. Triggers - "rust best practices", "is this idiomatic", "should this be a newtype", "anyhow or thiserror", "why does the borrow checker", "review this Rust".

The English summary is being prepared. Showing the original description.

See how to install

Files included (2)

  • SKILL.md3.3 KB
  • references/patterns.md8.1 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Rust best practices

One idea underneath every rule: a wrong program should not compile. Where a project also writes TypeScript, the same table lives one language over in typescript-best-practices. Rust hands you more of that for free, so the failures move: unwrap(), a clone() that silences the borrow checker, a stringly typed API, a blocking call on the async runtime.

RuleSummary
Enums with dataModel variants as an enum carrying each variant's payload. A struct of Option fields plus a bool admits states that cannot happen.
NewtypesWrap primitives that mean something: struct UserId(Uuid), struct Seconds(u32). Two String parameters in a row swap silently; two newtypes do not.
Parse at the edgeUntrusted bytes become a typed value once, at the boundary, with serde plus validation. Inside, trust the type. Bound the body before parsing.
Errors by layerA library returns its own enum error (thiserror), a binary composes with anyhow. Never Box<dyn Error> in a public signature you own.
No unwrap in library code? propagates, let ... else returns early. expect only for an invariant, with a message naming what was violated. Tests and main may panic.
Context, not stringly errorsAdd context as you propagate (.context("reading manifest")), keep the source chain. Formatting an error into a String early throws the cause away.
Borrow in, own outTake &str, &[T], impl IntoIterator. Return the owned type. A clone() added to end a borrow argument is a design smell; restructure the scope.
Deliberate visibilitypub(crate) by default. pub is an API promise. #[non_exhaustive] on a public enum or struct that will grow.
Conversions via traitsFrom/TryFrom rather than to_thing() helpers, so ? and generic code pick them up.
Don't block the runtimeNo file, SQLite, or CPU work on an async thread: spawn_blocking. Never hold a std::sync::Mutex guard across .await.
Cancellation safetyAnything inside select! may be dropped at any await point. Long work takes a cancellation token and honours it.
Iterators over index loopsExpress the transformation. Avoid collect() into a Vec you immediately iterate.
SAFETY on unsafeEvery unsafe block carries a // SAFETY: comment stating the invariant that makes it sound. No exceptions.
Secrets never in DebugA type holding a token, key or password gets a hand-written Debug that redacts. Derived Debug leaks into every log line.
Clippy is the floorcargo clippy --workspace --all-targets clean, warnings denied in CI. A lint you disagree with is suppressed at the line, with the reason.
Real testsUnit tests beside the code, integration tests in tests/. No sleep for synchronisation. Property tests where the invariant is stateable.

Examples: references/patterns.md.

Read the project's Cargo.toml lints table and its clippy configuration before deciding a rule here does not apply.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

One file, one job, and short enough to hold in your head. Covers the size policy (hard-split over 300 lines, split 200 to 300 at a seam, aim for 150), what a natural seam is and where to cut, the exemptions, the dependency rules that decide where the split lands, and the signals that a file is already two files. Use before adding to a file that is already long, when naming a new file, when a function has nowhere obvious to live, or when a review says a file is doing too much. Triggers - "this file is too long", "where should this go", "split this file", "is this file too big", "one responsibility".

The English summary is being prepared. Showing the original description.

kromatv/kroma60Updated Oct 19, 2026

naming

Free

What things get called. A file is named after its export in the project's case convention, a suffix is a resolution instruction rather than decoration, an index file only re-exports, and some symbol names are always wrong (utils, helpers, V2, Enhanced, New). Covers learning a tree's local vocabulary before adding to it, test and platform-variant naming, and the per-language conventions. Use when creating a file or directory, naming a test file, adding a platform variant, or when a name has to change. Triggers - "what should I call this file", "where does this file go", "naming convention", "kebab or camel", "name this test".

The English summary is being prepared. Showing the original description.

kromatv/kroma60Updated Oct 19, 2026

Spawn the comment hunter, fix accepted findings, and offer encodings for claimed constraints.

The English summary is being prepared. Showing the original description.

kromatv/kroma60Updated Oct 19, 2026

Write a short release note people finish reading. Picks the few changes a user will notice from the pull requests since the last release, names each by what the reader can now do, keeps to a length budget, writes every language from the intent instead of translating, and traces every line to a PR. Use when cutting a release, or filling a GitHub Release body, a store "what's new", a package changelog or an in-app what's new screen. Triggers - "write the release notes", "release notes for 0.4.0", "what's new", "changelog for this release", "notes de version".

The English summary is being prepared. Showing the original description.

kromatv/kroma60Updated Oct 19, 2026

Write cargo tests. A test name is a sentence, the body is setup, mock, test and verify blocks separated by blank lines with no comments, and shared setup lives in a named test-support module rather than in each test. Covers naming, the block shape, where a test file goes, async and time, workspaces, and running one crate or one filter. Use when adding or changing any #[test] or #[tokio::test], or when Rust coverage has to come up. Triggers - "write a rust test", "cargo test", "test this crate", "cover this handler".

The English summary is being prepared. Showing the original description.

kromatv/kroma60Updated Oct 19, 2026

Security guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts.

The English summary is being prepared. Showing the original description.

kromatv/kroma60Updated Oct 19, 2026

See all skills by kromatv

Report a problem with this skill