agentleFS
noverworknoverwork/noverterm/.claude/skills/rust-coder/SKILL.md

rust-coder

Skill2 starsChanged 15 days agoMITView on GitHub

Rust coding guide for this monorepo. Use when writing Rust code in any package (desktop, orm, relay, shared, update-signer). Combines Rust API Guidelines with clearly marked project rules for errors, Tokio, tracing, and Clippy. For GPUI code use gpui-coder; for schema changes use diesel-migration.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    [Official]: Use as_, to_, into_ consistently for conversions

    line 48
  2. Very specific:

    [Official]: Use iter, iter_mut, into_iter for iterator-producing methods

    line 49
  3. Very specific:

    [Official]: All public types should implement Debug

    line 50
  4. Distinctive:

    [Official]: Prefer private fields and controlled construction

    line 51
  5. Distinctive:

    [Official]: Avoid boolean flag parameters.

    line 52
  6. Very specific:

    [Official]: Use cargo fmt defaults; do not customize rustfmt casually

    line 56

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Coder - Convention Guide

Rust conventions for this monorepo.

  • Official = Rust API Guidelines / rustfmt / standard Rust conventions
  • Project = local rules for this repo
  • Common = widespread Rust practice, not a strict official requirement

Forbidden Patterns

// ❌ NEVER (Project)
unsafe {
    do_unsafe_work();
}

value.unwrap();
todo!();
dbg!(&value);

// ❌ AVOID IN LIBRARY CODE (Project)
value.expect("must exist");

Quick Reference

Naming

TypeConventionExampleSource
Files/dirssnake_casemessage_handler.rsOfficial
Types/traitsUpperCamelCaseMessageHandler, DeviceIdOfficial
Functions/varssnake_casehandle_message(), device_countOfficial
Constants/staticsSCREAMING_SNAKE_CASEMAX_RETRY_COUNTOfficial
Cargo crate namekebab-caseupdate-signerOfficial
Rust module pathsnake_caseupdate_signerOfficial

Key Rules

  1. [Project] No unwrap() outside tests — propagate with ?. The one exception is mutex.lock().unwrap(): a poisoned lock is already a crash
  2. [Project] expect("why this cannot fail") is allowed in tests and for startup invariants (the Tokio runtime, a backend task that panicked); not for input or I/O
  3. [Project] No unsafe in this repo
  4. [Official] Use as_, to_, into_ consistently for conversions
  5. [Official] Use iter, iter_mut, into_iter for iterator-producing methods
  6. [Official] All public types should implement Debug
  7. [Official] Prefer private fields and controlled construction
  8. [Official] Avoid boolean flag parameters; prefer domain types
  9. [Official] Destructors must not fail
  10. [Project] Async work runs on Tokio; log with tracing macros, never println!
  11. [Official] Public APIs should be documented and include examples where useful
  12. [Official] Use cargo fmt defaults; do not customize rustfmt casually

Error Handling

Two styles, by package (Project):

// packages/desktop: Result<T, String>. The string reaches the user, so say what failed.
pub fn init_pool(database_path: &Path) -> Result<DbPool, String> {
    r2d2::Pool::builder()
        .build(manager)
        .map_err(|error| format!("failed to open database: {error}"))
}

// packages/relay: anyhow at the binary's edge.
use anyhow::{Context, Result};

async fn connect(addr: &str) -> Result<TcpStream> {
    TcpStream::connect(addr)
        .await
        .with_context(|| format!("failed to connect to {addr}"))
}

Match the package you are in. Do not add anyhow or thiserror to desktop.

Async Pattern

// Blocking work (SQLite, file I/O) leaves the async thread.
tokio::task::spawn_blocking(move || operation(&mut connection)).await

// Log with structured fields, message last.
tracing::warn!(error, "Failed to save setting");

The desktop app owns one Tokio runtime (crate::app::runtime()); GPUI's executor is separate. UI code reaches backend futures through backend(...) in ui/bridge.rs (see gpui-coder).

Detailed References

  • Naming conventions (types, functions, traits, modules) → references/naming.md
  • Error handling (String errors, anyhow, domain errors, validation) → references/error-handling.md
  • Async & Tokio (spawning, cancellation, streams, tracing) → references/async-tokio.md
  • API design (constructors, builders, conversions, newtypes, traits) → references/api-design.md
  • Clippy & correctness (lint policy, commands, common fixes) → references/clippy.md
  • Anti-patterns (official + project anti-patterns, clearly labeled) → references/anti-patterns.md

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.