petekp/agent-skills/petekp-agent-skills-rust

Claude Code and agent skill by petekp/agent-skills

Trust tier 2
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Robust Rust patterns for file-backed data, parsing, persistence, FFI boundaries, and system integration. Use when writing Rust that handles file formats, subprocess integration, PID/process management, Serde serialization, or UniFFI boundaries. Covers UTF-8 safety, atomic writes, state machines, and defensive error handling.

Install

npx vskill@latest install petekp/agent-skills/petekp-agent-skills-rust

SKILL.md

Rust Engineering Guide

Patterns for building reliable Rust systems that handle file-backed data, external process integration, and cross-language boundaries.

Core Philosophy

Conservative by Default: Inputs from files, subprocesses, and external systems are untrusted.

  • Prefer false negatives over false positives
  • Same input → same output (deterministic)
  • Never panic on user machines due to bad input

Canonical Model Ownership: When Rust is the source of truth, maintain separate representations:

LayerPurposeCharacteristics
Internal domainBusiness logicExpressive enums, rich types
FFI DTOsCross-language boundaryFlat, stable, String-heavy
File formatPersistenceVersioned, round-trippable
External inputValidation boundaryStrictly validated, never trusted

Safe Rust Only: None of these patterns require unsafe. Use ecosystem crates for safe abstractions.


Reference Guides

Load the relevant reference when working in that domain:

DomainReferenceWhen to Load
Data Modelingreferences/data-modeling.mdSerde patterns, UniFFI, strong types, versioned schemas
File I/Oreferences/file-io.mdAtomic writes, concurrency control, file watching
Process Integrationreferences/process-integration.mdPID verification, subprocess handling, timestamps
Text & Parsingreferences/text-and-parsing.mdUTF-8 safety, path normalization, state machines
Testingreferences/testing.mdRound-trip tests, fuzz testing, Clippy lints

Error Handling

Library vs Application Errors

Libraries (public API): Use thiserror with granular error types per operation:

rust
// File operations have their own error type
#[derive(thiserror::Error, Debug)]
pub enum ReadError {
#[error("failed to read {path}")]
Io { path: PathBuf, #[source] source: std::io::Error },
#[error("parse error at line {line}: {message}")]
Parse { line: usize, message: String },
}
// Subprocess operations have their own error type
#[derive(thiserror::Error, Debug)]
pub enum SubprocessError {
#[error("failed to spawn process")]
Spawn(#[source] std::io::Error),
#[error("process exited with {code:?}: {stderr}")]
NonZeroExit { code: Option<i32>, stderr: String },
#[error("output not valid UTF-8")]
InvalidUtf8(#[source] std::str::Utf8Error),
#[error("timed out after {0:?}")]
Timeout(std::time::Duration),
}

Applications (internal/binary): Use anyhow for context-rich errors:

rust
use anyhow::{Context, Result};
fn load_config(path: &Path) -> Result<Config> {
let content = std::fs::read_to_string(path)
.with_context(|| format!("failed to read config from {}", path.display()))?;
// ...
}
Graceful Degradation

Errors degrade functionality, not crash. But log when being lenient:

rust
match parse_metadata(&line) {
Ok(meta) => entries.push(meta),
Err(e) => {
tracing::warn!("skipping malformed entry at line {}: {}", line_num, e);
// Continue processing other entries
}
}

Quick Reference

Do
  • Use std::sync::LazyLock for static regex (Rust 1.80+)
  • Hold locks across entire read-modify-write cycles
  • Add #[serde(deny_unknown_fields)] for strict external input
  • Truncate strings with .chars() or graphemes, not byte slicing
  • Write files atomically with sync_all() before rename
  • Verify PID identity with process start time
  • Use saturating_sub for time arithmetic
  • Run cargo clippy -- -D warnings and cargo fmt before commit
Don't
  • Use #[from] without adding context (loses which file failed)
  • Create monolithic error enums spanning unrelated operations
  • Silently ignore errors without logging
  • Slice strings with &s[..N] (panics on char boundaries)
  • Assume directory iteration order is stable
  • Trust subprocess output without validation
  • Use unsafe (not needed for these patterns)

Bugs This Guide Prevents

BugPatternReference
PID reuse "ghost sessions"Store + verify process start timeprocess-integration.md
Timestamp unit mismatch (sec vs ms)Normalize on readprocess-integration.md
UTF-8 panic on truncationUse .chars().take(n)text-and-parsing.md
Lost updates under concurrencyLock spans full read-modify-writefile-io.md
Corrupt file on power losssync_all() before renamefile-io.md
Silent metadata corruptionAnchor updates to heading linestext-and-parsing.md
Old data breaks new code#[serde(default)] + aliasdata-modeling.md

Change Checklist

When modifying these systems, verify:

Schema / Serde

  • [ ] New fields use Option + #[serde(default)]
  • [ ] Old field names supported via alias (read) or rename (write)
  • [ ] External input uses #[serde(deny_unknown_fields)]

Concurrency

  • [ ] Mutex held across entire read-modify-write cycle
  • [ ] Shared state uses Mutex<T>, not thread_local!
  • [ ] File locking documents platform caveats if used

Robustness

  • [ ] No panics on file I/O or parse errors
  • [ ] Errors logged before being ignored
  • [ ] Subprocesses have timeouts

Quality

  • [ ] cargo clippy -- -D warnings passes
  • [ ] cargo fmt --check passes
  • [ ] No unsafe blocks (unless justified and audited)

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
4
Repository forks
1
7-day trend score
8

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 3 May 2026, 6 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/petekp/agent-skills/petekp-agent-skills-rust/badge)](https://verified-skill.com/skills/petekp/agent-skills/petekp-agent-skills-rust)

Something wrong with this skill or its page? Tell us.