agentleFS
MicrosoftKnown publishermicrosoft/python-environment-tools/.github/skills/rust-coding-skill/SKILL.md

rust-coding-skill

Skill207 starsChanged 10 months agoMITView on GitHub

Use whenever editing Rust in PET to write allocation-aware, cross-platform, byte-safe code with behavior-proving tests.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. Newmcpe/rust-coding-skill★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository3 other files it gives its agents.

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. About 0 are common, 5 are distinctive, and 12 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 12

    Very specific

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

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

    Use this alongside rust-locator-patterns.

    line 8
  2. Very specific:

    Use Path/PathBuf for paths.

    line 16
  3. Distinctive:

    When adding or reviewing a path-keyed cache, check lookup, insert, remove, retain/prune, and state-sync paths.

    line 26
  4. Distinctive:

    Never calculate byte offsets from a transformed Unicode string and apply them to the original.

    line 30
  5. Very specific:

    Use to_ascii_lowercase rather than to_lowercase when the format is defined as ASCII.

    line 44
  6. Very specific:

    Prefer &str/&[u8] over cloning content between parsers.

    line 50
  7. Very specific:

    Prefer rfind/iterator operations over collecting an intermediate Vec just to select one item.

    line 51
  8. Very specific:

    Avoid format! and Unicode case conversion in per-line loops when ASCII matching or direct writes suffice.

    line 52
  9. Distinctive:

    Do not claim an optimization is complete until every relevant call path is traced, including base/root environments and manager lookup.

    line 53
  10. Distinctive:

    Do not emit the same warning, telemetry event, or report from both a pre-check and the worker path.

    line 54
  11. Very specific:

    Use contextual expect for poisoned locks in production code, matching the surrounding crate.

    line 60
  12. Very specific:

    Use #[cfg(...)] for platform-only code.

    line 64
  13. Very specific:

    Avoid canonicalize for Windows junction identity.

    line 65
  14. Very specific:

    Treat both / and \ as separators when parsing user patterns, but only classify ` as recursive when it is a complete path segment.

    line 66
  15. Distinctive:

    Prefer raw string literals for regexes and backslash-heavy path examples to avoid malformed escapes.

    line 68
  16. Very specific:

    Before documenting or logging a recommended config value, trace how the consumer uses it.

    line 69
  17. Very specific:

    Before every Rust commit, run targeted tests and invoke the rust-precommit skill.

    line 96

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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

PET Rust Coding Skill

Use this alongside rust-locator-patterns. Priority order:

  1. Readable code with explicit invariants
  2. Correct cross-platform and concurrent behavior
  3. Measured performance improvements without duplicate work

Path Identity and Caches

Use Path/PathBuf for paths. Preserve the caller-facing path in reported values, but normalize cache and comparison keys with existing PET helpers such as norm_case.

A normalized key does not imply the cached value can expose the first caller's spelling:

let key = norm_case(path);
let mut cached = cache.get(&key)?.clone();
cached.prefix = Some(path.to_path_buf());

When adding or reviewing a path-keyed cache, check lookup, insert, remove, retain/prune, and state-sync paths. Add Windows coverage using equivalent separators or casing; do not test only the happy-path spelling.

Byte-Safe Parsing

Never calculate byte offsets from a transformed Unicode string and apply them to the original. Unicode case conversion can change byte length.

For ASCII wire/file markers, use byte-stable ASCII-insensitive matching and checked slicing:

let marker = b"# cmd:";
let start = line
    .as_bytes()
    .windows(marker.len())
    .position(|window| window.eq_ignore_ascii_case(marker))?
    + marker.len();
let value = line.get(start..)?.trim();

Use to_ascii_lowercase rather than to_lowercase when the format is defined as ASCII. Add a non-ASCII path regression test whenever offsets are derived from textual markers.

Hot-Path I/O and Allocations

Discovery runs frequently and in parallel. Before adding a cache, prove the repeated work and define invalidation. Within one operation, read immutable metadata once and pass borrowed snapshots through parsers.

  • Prefer &str/&[u8] over cloning content between parsers.
  • Prefer rfind/iterator operations over collecting an intermediate Vec just to select one item.
  • Avoid format! and Unicode case conversion in per-line loops when ASCII matching or direct writes suffice.
  • Do not claim an optimization is complete until every relevant call path is traced, including base/root environments and manager lookup.
  • Do not emit the same warning, telemetry event, or report from both a pre-check and the worker path.

Error Handling and Locks

Library code should preserve typed information where repository APIs permit it. Prefer ?, let-else, and if let over broad fallbacks. Do not swallow filesystem errors when doing so can make stale cache data look valid.

Use contextual expect for poisoned locks in production code, matching the surrounding crate. Keep lock scopes short and never perform filesystem I/O or callbacks while holding a shared-state lock unless the design explicitly requires it.

Cross-Platform Semantics

  • Use #[cfg(...)] for platform-only code; cfg! does not prevent compilation.
  • Avoid canonicalize for Windows junction identity; use PET path helpers.
  • Treat both / and \ as separators when parsing user patterns, but only classify ** as recursive when it is a complete path segment. foo**bar is not a recursive segment.
  • Preserve original user-facing paths after normalized comparisons.
  • Prefer raw string literals for regexes and backslash-heavy path examples to avoid malformed escapes.
  • Before documenting or logging a recommended config value, trace how the consumer uses it. For example, environmentDirectories contains directories that hold environments, not environment folders themselves.

Subprocess Ownership

Keep Windows probe children suspended until job assignment succeeds, and fail closed if the primary thread cannot be identified. On stable Rust, a per-process PssCaptureSnapshot(PSS_CAPTURE_THREADS) can supply thread metadata without a system-wide Toolhelp scan or address-space clone; benchmark the launch boundary against the exact base on the same host rather than assuming enumeration is cheap. CommandExt::creation_flags replaces existing flags, so any runner-controlled flag contract must be explicit and tested. On Unix, signal the owned process group before reaping its leader (waitid with WNOWAIT preserves the PID until then), never after the numeric group ID could be reused.

On Darwin, signalling a zombie-only group can return EPERM; never suppress that error without proving there are no live members. proc_pidinfo(PROC_PIDTBSDINFO) requires a nonzero argument to include zombies, and any group inspection must remain bounded and revalidate member birth identities rather than trusting PIDs alone.

For descendant-lifetime tests, use a readiness handshake and an OS-owned resource such as a file lock that is released on exit. Do not equate Unix PID disappearance with termination: grandchildren can be dead but still awaiting reaping by their parent or the OS reaper.

Tests Must Prove the Change

Tests should demonstrate the behavior or performance invariant, not merely execute new lines.

For optimizations, instrument the dependency boundary and assert the operation count:

let reads = AtomicUsize::new(0);
parse_with_reader(path, |_| {
    reads.fetch_add(1, Ordering::Relaxed);
    Some(history.clone())
});
assert_eq!(reads.load(Ordering::Relaxed), 1);

For parser helpers, include malformed input, non-ASCII surrounding data, and case variations. For diagnostics, test pattern classification and expansion filtering separately. Keep temp paths unique with tempfile or process/counter-based names.

Before every Rust commit, run targeted tests and invoke the rust-precommit skill. Keep that skill as the single source of truth for required format and Clippy commands.

Learnings

Do not execute freshly written scripts as concurrent Unix subprocess fixtures: spawning can fail with ETXTBSY (Text file busy). Prefer an existing interpreter such as /bin/sh -c with an inline script, or the existing test executable. Assert the typed runner outcome before checking an optional parsed result, so a spawn failure cannot masquerade as a successful negative parsing or timeout test.

For real-pipe EOF/EPIPE tests, create the pipe inside an isolated test subprocess when other test threads spawn children. Unix CLOEXEC closes descriptors at exec, not fork: a concurrent child can temporarily retain a reader, allowing the only write to succeed before the final reader disappears. A readiness handshake alone does not prevent this race. Keep the operation's measured deadline separate from setup, and make an outer fixture deadline cover readiness, waits both before and after forced termination, reader joins, and fallback Drop cleanup.

Use a per-worktree Cargo target directory when validating stacked changes so native fixtures cannot execute another worktree's stale binary. On WSL, run timing-sensitive Linux binaries from the native Linux filesystem rather than a Windows mount, where page faults can stall in filesystem RPC. When launching instrumented PET with env_clear(), retain LLVM_PROFILE_FILE exactly so child coverage reaches the collector instead of an uncollected default profile.

LLVM LCOV summaries are not necessarily counts of unique DA source entries: a native export can have LF=191, LH=173, 181 mapped lines, and 177 positive mapped lines. Do not reject valid exports using summary/source equality or silently drop unmapped entries; preserve the raw exact-base gate and follow the conservative supplemental accounting documented in Quality snapshots. Prove subprocess collection with exact-PID profiles and isolated idle/request counter differences, not a whole-workspace percentage increase.

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.