Skip to content

Commit c4f83c9

Browse files
karthiknadigCopilot
andcommitted
docs: address Rust skill review feedback (PR #497)
Use supported frontmatter, standard-library parsing examples, atomic counters, and the existing pre-commit skill as the single source of truth. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2ce9eb4 commit c4f83c9

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

  • .github/skills/rust-coding-skill

.github/skills/rust-coding-skill/SKILL.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
name: "rust-coding-skill"
33
description: "Use whenever editing Rust in PET to write allocation-aware, cross-platform, byte-safe code with behavior-proving tests."
4-
user-invocable: true
54
---
65

76
# PET Rust Coding Skill
@@ -33,9 +32,13 @@ Never calculate byte offsets from a transformed Unicode string and apply them to
3332
For ASCII wire/file markers, use byte-stable ASCII-insensitive matching and checked slicing:
3433

3534
```rust
36-
let start = find_ascii_case_insensitive(line, "# cmd:")? + "# cmd:".len();
37-
let end = find_ascii_case_insensitive(line, " create -")?;
38-
let value = line.get(start..end)?.trim();
35+
let marker = b"# cmd:";
36+
let start = line
37+
.as_bytes()
38+
.windows(marker.len())
39+
.position(|window| window.eq_ignore_ascii_case(marker))?
40+
+ marker.len();
41+
let value = line.get(start..)?.trim();
3942
```
4043

4144
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.
@@ -70,14 +73,14 @@ Tests should demonstrate the behavior or performance invariant, not merely execu
7073
For optimizations, instrument the dependency boundary and assert the operation count:
7174

7275
```rust
73-
let reads = Cell::new(0);
76+
let reads = AtomicUsize::new(0);
7477
parse_with_reader(path, |_| {
75-
reads.set(reads.get() + 1);
78+
reads.fetch_add(1, Ordering::Relaxed);
7679
Some(history.clone())
7780
});
78-
assert_eq!(reads.get(), 1);
81+
assert_eq!(reads.load(Ordering::Relaxed), 1);
7982
```
8083

8184
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.
8285

83-
Before every Rust commit, run the targeted tests plus `scripts/rust-precommit.ps1` (or `.sh`). Do not suppress Clippy warnings to land a change.
86+
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.

0 commit comments

Comments
 (0)