[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M69BNGJAVCG7WA93S1NK68AW":3,"skill-same:01M69BNGJAVCG7WA93S1NK68AW":63},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":18,"categories":19,"keywords":30,"publishedAt":35,"linkOnly":36,"markdownContent":37,"markdownBody":38,"frontMatter":39,"refName":40,"commitSha":41,"skillDirectory":42,"forksCount":43,"repositoryHtmlUrl":44,"repositoryHomepageUrl":17,"ownerHtmlUrl":45,"ownerBlogUrl":46,"ownerDescription":47,"updatedAt":48,"install":49,"resources":62},"01M69BNGJAVCG7WA93S1NK68AW","rust-coding-skill","PET 项目 Rust 编码","Use whenever editing Rust in PET to write allocation-aware, cross-platform, byte-safe code with behavior-proving tests.","在 PET 中编辑 Rust 代码时使用，以编写具备分配感知、跨平台、字节安全的代码，并附带可证明行为正确性的测试。","microsoft\u002Fpython-environment-tools","microsoft","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6154722?v=4","01M698VYDXZ6JW5WH3CRV650R8","Microsoft","01M69BNE8385D7YQ637S4PQEQ7",209,"MIT",null,"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-coding-skill\u002FSKILL.md",[20,25],{"categoryNo":21,"categoryName":22,"taxonomyType":23,"taxonomyTypeDesc":24},"01M8BQ6TQZN6R52WBJ9H8NRMQM","软件开发工程师","PROFESSION","适用职业",{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},"01M8BSNPHVX9Y1H3B2ZX3V06RF","Rust 开发","SCENARIO","使用场景",[31,32,33,34],"rust","rust coding skill","safe","code","2026-11-10 10:12:30",false,"---\nname: \"rust-coding-skill\"\ndescription: \"Use whenever editing Rust in PET to write allocation-aware, cross-platform, byte-safe code with behavior-proving tests.\"\n---\n\n# PET Rust Coding Skill\n\nUse this alongside `rust-locator-patterns`. Priority order:\n\n1. Readable code with explicit invariants\n2. Correct cross-platform and concurrent behavior\n3. Measured performance improvements without duplicate work\n\n## Path Identity and Caches\n\nUse `Path`\u002F`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`.\n\nA normalized key does not imply the cached value can expose the first caller's spelling:\n\n```rust\nlet key = norm_case(path);\nlet mut cached = cache.get(&key)?.clone();\ncached.prefix = Some(path.to_path_buf());\n```\n\nWhen adding or reviewing a path-keyed cache, check lookup, insert, remove, retain\u002Fprune, and state-sync paths. Add Windows coverage using equivalent separators or casing; do not test only the happy-path spelling.\n\n## Byte-Safe Parsing\n\nNever calculate byte offsets from a transformed Unicode string and apply them to the original. Unicode case conversion can change byte length.\n\nFor ASCII wire\u002Ffile markers, use byte-stable ASCII-insensitive matching and checked slicing:\n\n```rust\nlet marker = b\"# cmd:\";\nlet start = line\n    .as_bytes()\n    .windows(marker.len())\n    .position(|window| window.eq_ignore_ascii_case(marker))?\n    + marker.len();\nlet value = line.get(start..)?.trim();\n```\n\nUse `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.\n\n## Hot-Path I\u002FO and Allocations\n\nDiscovery 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.\n\n- Prefer `&str`\u002F`&[u8]` over cloning content between parsers.\n- Prefer `rfind`\u002Fiterator operations over collecting an intermediate `Vec` just to select one item.\n- Avoid `format!` and Unicode case conversion in per-line loops when ASCII matching or direct writes suffice.\n- Do not claim an optimization is complete until every relevant call path is traced, including base\u002Froot environments and manager lookup.\n- Do not emit the same warning, telemetry event, or report from both a pre-check and the worker path.\n\n## Error Handling and Locks\n\nLibrary 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.\n\nUse contextual `expect` for poisoned locks in production code, matching the surrounding crate. Keep lock scopes short and never perform filesystem I\u002FO or callbacks while holding a shared-state lock unless the design explicitly requires it.\n\n## Cross-Platform Semantics\n\n- Use `#[cfg(...)]` for platform-only code; `cfg!` does not prevent compilation.\n- Avoid `canonicalize` for Windows junction identity; use PET path helpers.\n- Treat both `\u002F` 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.\n- Preserve original user-facing paths after normalized comparisons.\n- Prefer raw string literals for regexes and backslash-heavy path examples to avoid malformed escapes.\n- 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.\n\n## Subprocess Ownership\n\nKeep 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.\n\nOn 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.\n\nFor 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.\n\n## Tests Must Prove the Change\n\nTests should demonstrate the behavior or performance invariant, not merely execute new lines.\n\nFor optimizations, instrument the dependency boundary and assert the operation count:\n\n```rust\nlet reads = AtomicUsize::new(0);\nparse_with_reader(path, |_| {\n    reads.fetch_add(1, Ordering::Relaxed);\n    Some(history.clone())\n});\nassert_eq!(reads.load(Ordering::Relaxed), 1);\n```\n\nFor 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\u002Fcounter-based names.\n\nBefore 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.\n\n## Learnings\n\nDo not execute freshly written scripts as concurrent Unix subprocess fixtures: spawning can fail with `ETXTBSY` (Text file busy). Prefer an existing interpreter such as `\u002Fbin\u002Fsh -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.\n\nFor real-pipe EOF\u002FEPIPE 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.\n\nUse 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.\n\nLLVM 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\u002Fsource equality or silently drop unmapped entries; preserve the raw exact-base gate and follow the conservative supplemental accounting documented in [Quality snapshots](..\u002F..\u002F..\u002Fdocs\u002FQUALITY_SNAPSHOTS.md#production-focused-and-subprocess-evidence). Prove subprocess collection with exact-PID profiles and isolated idle\u002Frequest counter differences, not a whole-workspace percentage increase.\n","# PET Rust Coding Skill\n\nUse this alongside `rust-locator-patterns`. Priority order:\n\n1. Readable code with explicit invariants\n2. Correct cross-platform and concurrent behavior\n3. Measured performance improvements without duplicate work\n\n## Path Identity and Caches\n\nUse `Path`\u002F`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`.\n\nA normalized key does not imply the cached value can expose the first caller's spelling:\n\n```rust\nlet key = norm_case(path);\nlet mut cached = cache.get(&key)?.clone();\ncached.prefix = Some(path.to_path_buf());\n```\n\nWhen adding or reviewing a path-keyed cache, check lookup, insert, remove, retain\u002Fprune, and state-sync paths. Add Windows coverage using equivalent separators or casing; do not test only the happy-path spelling.\n\n## Byte-Safe Parsing\n\nNever calculate byte offsets from a transformed Unicode string and apply them to the original. Unicode case conversion can change byte length.\n\nFor ASCII wire\u002Ffile markers, use byte-stable ASCII-insensitive matching and checked slicing:\n\n```rust\nlet marker = b\"# cmd:\";\nlet start = line\n    .as_bytes()\n    .windows(marker.len())\n    .position(|window| window.eq_ignore_ascii_case(marker))?\n    + marker.len();\nlet value = line.get(start..)?.trim();\n```\n\nUse `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.\n\n## Hot-Path I\u002FO and Allocations\n\nDiscovery 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.\n\n- Prefer `&str`\u002F`&[u8]` over cloning content between parsers.\n- Prefer `rfind`\u002Fiterator operations over collecting an intermediate `Vec` just to select one item.\n- Avoid `format!` and Unicode case conversion in per-line loops when ASCII matching or direct writes suffice.\n- Do not claim an optimization is complete until every relevant call path is traced, including base\u002Froot environments and manager lookup.\n- Do not emit the same warning, telemetry event, or report from both a pre-check and the worker path.\n\n## Error Handling and Locks\n\nLibrary 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.\n\nUse contextual `expect` for poisoned locks in production code, matching the surrounding crate. Keep lock scopes short and never perform filesystem I\u002FO or callbacks while holding a shared-state lock unless the design explicitly requires it.\n\n## Cross-Platform Semantics\n\n- Use `#[cfg(...)]` for platform-only code; `cfg!` does not prevent compilation.\n- Avoid `canonicalize` for Windows junction identity; use PET path helpers.\n- Treat both `\u002F` 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.\n- Preserve original user-facing paths after normalized comparisons.\n- Prefer raw string literals for regexes and backslash-heavy path examples to avoid malformed escapes.\n- 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.\n\n## Subprocess Ownership\n\nKeep 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.\n\nOn 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.\n\nFor 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.\n\n## Tests Must Prove the Change\n\nTests should demonstrate the behavior or performance invariant, not merely execute new lines.\n\nFor optimizations, instrument the dependency boundary and assert the operation count:\n\n```rust\nlet reads = AtomicUsize::new(0);\nparse_with_reader(path, |_| {\n    reads.fetch_add(1, Ordering::Relaxed);\n    Some(history.clone())\n});\nassert_eq!(reads.load(Ordering::Relaxed), 1);\n```\n\nFor 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\u002Fcounter-based names.\n\nBefore 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.\n\n## Learnings\n\nDo not execute freshly written scripts as concurrent Unix subprocess fixtures: spawning can fail with `ETXTBSY` (Text file busy). Prefer an existing interpreter such as `\u002Fbin\u002Fsh -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.\n\nFor real-pipe EOF\u002FEPIPE 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.\n\nUse 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.\n\nLLVM 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\u002Fsource equality or silently drop unmapped entries; preserve the raw exact-base gate and follow the conservative supplemental accounting documented in [Quality snapshots](..\u002F..\u002F..\u002Fdocs\u002FQUALITY_SNAPSHOTS.md#production-focused-and-subprocess-evidence). Prove subprocess collection with exact-PID profiles and isolated idle\u002Frequest counter differences, not a whole-workspace percentage increase.\n",{"name":5,"description":7},"main","02dd29e49e3c71d4ec06e1072d6331494a12e01d",".github\u002Fskills\u002Frust-coding-skill",48,"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools","https:\u002F\u002Fgithub.com\u002Fmicrosoft","https:\u002F\u002Fopensource.microsoft.com","Open source projects and samples from Microsoft","2026-11-10 02:07:34",{"source":9,"skillName":5,"commands":50,"prompt":60,"zipAvailable":61},[51,54,57],{"tool":52,"command":53},"npx","npx skills add microsoft\u002Fpython-environment-tools --skill rust-coding-skill",{"tool":55,"command":56},"bunx","bunx skills add microsoft\u002Fpython-environment-tools --skill rust-coding-skill",{"tool":58,"command":59},"pnpm","pnpm dlx skills add microsoft\u002Fpython-environment-tools --skill rust-coding-skill","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-coding-skill\u002FSKILL.md",true,[],[64,80],{"skillNo":65,"name":66,"nameZh":67,"description":68,"descriptionZh":69,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":70,"categories":71,"keywords":74,"publishedAt":35},"01M69BNM2MW8C61MRH902Q9BRQ","rust-precommit","Rust 预提交检查","Run the mandatory PET Rust pre-commit checks (cargo fmt + cargo clippy -D warnings) before every commit. Invoke whenever you are about to commit Rust changes, after applying review feedback, or whenever you need to verify formatting and lint cleanliness.","在每次提交前运行强制性的 PET Rust 预提交检查（cargo fmt + cargo clippy -D warnings）。当即将提交 Rust 更改、应用审查反馈后，或需要验证格式和 lint 是否干净时调用。","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-precommit\u002FSKILL.md",[72,73],{"categoryNo":21,"categoryName":22,"taxonomyType":23,"taxonomyTypeDesc":24},{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},[31,75,76,77,78,79],"rust precommit","review","commit","run","lint",{"skillNo":81,"name":82,"nameZh":83,"description":84,"descriptionZh":85,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":86,"categories":87,"keywords":90,"publishedAt":35},"01M69BNJ1P2BKGDBMAZBT6S0AF","rust-locator-patterns","PET Rust 编码规范","PET (Python Environment Tools) Rust coding conventions: locator ordering, thread safety, platform gating, JSONRPC rules, version detection, and path\u002Fsymlink handling. Reference when writing or reviewing Rust code in this repo to avoid convention violations that cause review churn.","PET（Python Environment Tools）Rust 编码约定：定位器顺序、线程安全、平台门控、JSONRPC 规则、版本检测以及路径\u002F符号链接处理。在本仓库编写或审查 Rust 代码时参考，以避免违反约定而导致审查反复修改。","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-locator-patterns\u002FSKILL.md",[88,89],{"categoryNo":21,"categoryName":22,"taxonomyType":23,"taxonomyTypeDesc":24},{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},[31,91,92,76,93,34],"rust locator patterns","writing","python"]