Skip to content
Back to search

rust-ownership-optimizer

Guides AI coding agents on Rust ownership, borrowing, lifetimes, and memory optimization; reduces unnecessary clones and allocations by leveraging compile-time ownership analysis. Use when writing, reviewing, or refactoring Rust code, when fixing borrow checker errors (E0382, E0499, E0502, E0505, E0506, E0507, E0515, E0597, E0716, E0106), or when code contains `.clone()`, `Box`, `Rc`, `RefCell`, `Arc`, `Mutex`, `to_string()`, or `to_owned()`.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/ichbinrather--rust-ownership-optimizer/badge.svg)](/listings/ichbinrather--rust-ownership-optimizer)

HTML

<a href="/listings/ichbinrather--rust-ownership-optimizer"><img src="/api/listings/ichbinrather--rust-ownership-optimizer/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Windows

git clone https://github.com/ichbinrather/rust-ownership-optimizer.git
cd rust-ownership-optimizer
powershell -ExecutionPolicy Bypass -File .\install.ps1

macOS / Linux

git clone https://github.com/ichbinrather/rust-ownership-optimizer.git
cd rust-ownership-optimizer
./install.sh

The script looks for the config folders of the supported agents (`.claude`, `.codex`, `.cursor`, ...) in your home directory and copies the skill into each one it finds. Restart the agent afterwards.

Options:

- `-Link` / `--link`: link to the clone instead of copying it, so `git pull` updates the skill. On Windows this creates a directory junction, which does not need admin rights. - `-All` / `--all`: also install for agents whose folder does not exist yet. - `-Force` / `--force`: overwrite an existing install.

If you have Node.js, `npx skills add ichbinrather/rust-ownership-optimizer` works too.

Installing by hand

Copy the repository into the agent's skills folder under the name `rust-ownership-optimizer`, so that `SKILL.md` ends up directly inside it.

| Agent | Skills folder | |-------|---------------| | Claude Code | `~/.claude/skills` | | Codex CLI | `~/.codex/skills` or `~/.agents/skills` | | OpenCode | `~/.config/opencode/skills` | | Cursor | `~/.cursor/skills` | | Gemini CLI | `~/.gemini/skills` | | GitHub Copilot | `~/.copilot/skills` |

On Windows, `~` is `%USERPROFILE%`. These paths have moved between agent versions before, so check your agent's docs if the skill does not show up.

To use it in a single project, put it in `.claude/skills/` inside the repository and copy `AGENTS.md` to the project root. Agents without skill support can use the rules in `AGENTS.md` directly: paste them into `.github/copilot-instructions.md`, `.cursor/rules/`, `GEMINI.md`, `.windsurf/rules/`, or `.clinerules/`.

Checking that it loaded

Restart the agent and ask which skills it has, or call it by name (`/rust-ownership-optimizer` in Claude Code, `$rust-ownership-optimizer` in Codex). On a Rust project, ask it to review a file for unnecessary clones. Findings come back like this:

[clone] src/report.rs:42: report cloned for a read-only call -> take &Report
[box] src/shapes.rs:10: Box<dyn Shape> parameter only borrowed -> &dyn Shape

Updating and removing

With a linked install, `git pull` is enough. With a copied install, pull and run the installer again with `-Force` / `--force`.

To remove it, delete `rust-ownership-optimizer` from the agent's skills folder. If you installed with `-Link` on Windows, remove the junction with `cmd /c rmdir <path>`. In Windows PowerShell 5.1, `Remove-Item -Recurse` on a junction can delete the files in your clone as well.

If PowerShell says that running scripts is disabled, use the `-ExecutionPolicy Bypass` form shown above. It applies to that single run only.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 236 lines
  1. ---
  2. name: rust-ownership-optimizer
  3. description: Guides AI coding agents on Rust ownership, borrowing, lifetimes, and memory optimization; reduces unnecessary clones and allocations by leveraging compile-time ownership analysis. Use when writing, reviewing, or refactoring Rust code, when fixing borrow checker errors (E0382, E0499, E0502, E0505, E0506, E0507, E0515, E0597, E0716, E0106), or when code contains `.clone()`, `Box`, `Rc`, `RefCell`, `Arc`, `Mutex`, `to_string()`, or `to_owned()`.
  4. license: MIT
  5. metadata:
  6. version: "0.4.0"
  7. ---
  8. # Rust Ownership Optimizer
  9. ## Core Principle
  10. Rust has **no garbage collector and no runtime memory manager**. Memory is managed by
  11. **compile-time ownership analysis**: the compiler (borrow checker) proves at compile time
  12. who owns each value, how long each reference lives, and exactly where each value is
  13. dropped. Deallocation is deterministic and inserted by the compiler at scope end (RAII).
  14. Never describe Rust memory management with terms borrowed from runtime-managed
  15. languages. Never write "the value is collected", "the collector frees it", or similar.
  16. Say "the value is dropped at the end of its owner's scope".
  17. Your goal: produce code that satisfies the borrow checker **by design**, not by
  18. copying data until the errors disappear.
  19. ## The Ownership Rules (always apply)
  20. 1. Each value has exactly one owner.
  21. 2. When the owner goes out of scope, the value is dropped.
  22. 3. At any time, a value has **either** any number of shared references (`&T`) **or**
  23. exactly one mutable reference (`&mut T`), never both.
  24. 4. A reference must never outlive the value it points to.
  25. ## Workflow
  26. Follow these steps for every Rust task in scope.
  27. 1. **Ask the ownership question first.** Before touching code, answer:
  28. *Who should own this data, and for how long?* Classify the value:
  29. - **Unique entity** (has identity, one place of truth): one owner, others borrow.
  30. - **Value object** (small, interchangeable): `Copy` or a cheap `clone()` is fine.
  31. - **Shared immutable data** (config, audit records, lookup tables): `Arc<T>` / `Rc<T>`
  32. or plain `&T` with a lifetime, never deep copies.
  33. - **Temporary** (intermediate result): restructure so it is never stored.
  34. 2. **Map the compiler error to a design question**, not to a quick fix.
  35. See `references/error-codes.md`.
  36. 3. **Apply the review checklist** below.
  37. 4. **Verify** with `cargo check` and Clippy (see Verification).
  38. 5. **Check your own diff** with the ownership guard before you finish (see Diff Guard).
  39. This matters most when the borrow error was a side issue in a larger task.
  40. 6. **Escalate after three failed attempts.** If the same borrow error survives three
  41. local fixes, stop patching. Re-examine the data model: ownership roles, struct
  42. boundaries, or whether the data should be split, indexed, or shared.
  43. ## Decision Order for Parameters and Fields
  44. Pick the **first** option that compiles and expresses the intent:
  45. | Need | Use | Runtime cost |
  46. |------|-----|--------------|
  47. | Read only | `&T`, `&str`, `&[T]`, `&Path` | none |
  48. | Modify in place | `&mut T` | none |
  49. | Store or consume the value | `T` (caller moves in) | none (move) |
  50. | Usually borrowed, sometimes modified | `Cow<'_, T>` | allocation only on write |
  51. | Accept many input types | `impl AsRef<T>` / `impl Into<T>` | none / conversion |
  52. | Shared ownership, single thread | `Rc<T>` | non-atomic count |
  53. | Shared ownership, multi thread | `Arc<T>` | atomic count |
  54. | Mutation behind shared ownership | `Cell` / `RefCell` / `Mutex` / `RwLock` | runtime check (last resort) |
  55. Prefer borrowed slice types in signatures: `&str` over `&String`, `&[T]` over `&Vec<T>`,
  56. `&Path` over `&PathBuf`.
  57. ## Review Checklist
  58. ### 1. Unnecessary `clone()`
  59. Flag a `.clone()` (or `.to_string()`, `.to_owned()`, `.to_vec()`) when:
  60. - The clone is passed to a function that only reads it. Fix: change the parameter to `&T`.
  61. - The original is never used after the clone. Fix: move the original instead.
  62. - The clone exists only to silence E0382 (use after move). Fix: reorder code, borrow, or
  63. restructure so the last use moves.
  64. - The clone is inside a loop over a collection that could be iterated by reference
  65. (`for x in &items`) or consumed (`for x in items`).
  66. - A `String` is cloned only to be compared or hashed. Fix: compare `&str`.
  67. - An `Option<T>` / `Result<T, E>` is cloned to inspect it. Fix: `.as_ref()`, `.as_deref()`,
  68. `if let Some(x) = &opt`.
  69. - A struct field is cloned out to call a method while `self` is borrowed. Fix: borrow
  70. disjoint fields separately, or use `std::mem::take` / `std::mem::replace`.
  71. A clone is **justified** when: the value is a cheap value object, two owners genuinely
  72. need independent copies, the data crosses a thread boundary without `Arc`, or the clone
  73. is of an `Rc`/`Arc` (a reference-count increment, not a deep copy). Write `Rc::clone(&x)`
  74. to make that explicit.
  75. ### 2. Unnecessary `Box`
  76. Flag `Box<T>` when:
  77. - `T` is a sized value used only locally (`let x = Box::new(5);`). Use the value directly.
  78. - `Box<Vec<T>>`, `Box<String>`, `Box<HashMap<..>>`: these already own heap storage.
  79. - A parameter is `Box<dyn Trait>` but the function only uses the value during the call.
  80. Take a reference instead: `&dyn Trait` or `&impl Trait`. Both avoid the allocation.
  81. - A function returns `Box<dyn Iterator>` where `impl Iterator` works.
  82. `&dyn Trait` and generics are both fine; the problem is the `Box`, not the `dyn`. Do not
  83. rewrite working `&dyn` code into generics just for static dispatch. Prefer generics only
  84. when the call is in a measured hot path, and keep `&dyn` when it avoids duplicated code
  85. from monomorphization or keeps compile times and binary size down.
  86. `Box` is **justified** for: recursive types (`enum List { Cons(i32, Box<List>), Nil }`),
  87. heterogeneous collections of trait objects, very large values moved often, and
  88. `Box<dyn Error>` at application boundaries.
  89. ### 3. Borrow Conflicts
  90. Fix these patterns without cloning:
  91. - **Shared + mutable overlap (E0502, E0499):** finish the read, keep the small value you
  92. need (an index, a `Copy` value, `len()`), then mutate. A borrow ends at its last use
  93. (non-lexical lifetimes), so shorten the borrow instead of copying the data.
  94. - **Mutating a collection while iterating it:** use `retain`, `retain_mut`, `drain(..)`,
  95. `iter_mut()`, `split_at_mut`, or collect indices first and apply after.
  96. - **Two fields of `self`:** access fields directly (`&mut self.a`, `&self.b`) instead of
  97. through getters that borrow all of `self`.
  98. - **Map lookup then insert:** use the `entry()` API.
  99. - **Moving out of a reference (E0507):** use `std::mem::take`, `mem::replace`,
  100. `Option::take`, or borrow the inner value.
  101. - **Value does not live long enough (E0597, E0716, E0515):** bind temporaries to a name,
  102. move the owner to a wider scope, or return owned data.
  103. ### 4. Allocations
  104. Measure before micro-optimizing: algorithm and data structure choices outweigh
  105. allocation tweaks. Then:
  106. - Pre-size: `Vec::with_capacity(n)`, `String::with_capacity(n)`.
  107. - Avoid `collect::<Vec<_>>()` when the result is iterated once: chain iterators.
  108. - Build strings with `push_str` / `write!` in loops, not repeated `format!` or `+`.
  109. - Return `&str` / `&[T]` views into existing data instead of new `String` / `Vec`.
  110. - Use `Cow<'_, str>` when a function usually returns its input unchanged.
  111. - Benchmark only in `--release`.
  112. ### 5. Lifetimes
  113. - Rely on lifetime elision first. Add explicit lifetimes only when the compiler needs them.
  114. - Never use `'static` to silence an error unless the data truly lives for the whole program.
  115. - A struct holding references (`struct Parser<'a> { input: &'a str }`) avoids copying.
  116. Use it for short-lived views.
  117. - If annotations grow complex, reconsider ownership: the struct may need to own its data.
  118. ### 6. Smart Pointers and Interior Mutability
  119. - `Rc<RefCell<T>>` everywhere signals an ownership design problem. Try a single owner
  120. with borrowed access, an arena with indices, or message passing first.
  121. - `RefCell` moves borrow checks to runtime and can panic. State why compile-time checks
  122. are not possible before using it. Prefer `Cell<T>` for `Copy` values.
  123. - Read-heavy `Arc<Mutex<T>>`: consider `RwLock`, or share an immutable `Arc<T>`.
  124. - Break reference cycles with `Weak<T>`, or the values are never dropped.
  125. ## Output Format
  126. When reviewing code, report each finding as:
  127. ```
  128. [category] location: problem -> fix (why it is cheaper or safer)
  129. ```
  130. Categories: `clone`, `box`, `borrow`, `alloc`, `lifetime`, `smart-ptr`.
  131. Then show the optimized code. Keep behavior identical. If a change alters the public
  132. API (for example a `String` parameter becomes `&str`), say so.
  133. ## Verification
  134. Run when a Cargo project is available. The commands work the same in PowerShell, cmd,
  135. and POSIX shells:
  136. ```
  137. cargo check
  138. cargo clippy --all-targets -- -W clippy::redundant_clone -W clippy::implicit_clone -W clippy::unnecessary_to_owned -W clippy::needless_pass_by_value -W clippy::box_collection -W clippy::boxed_local
  139. cargo test
  140. ```
  141. For the full ownership lint set, run the bundled script from the project root:
  142. `scripts/audit.ps1` on Windows, `scripts/audit.sh` on macOS and Linux.
  143. `clippy::redundant_clone` and `clippy::needless_collect` are in Clippy's nursery group
  144. and can report false positives. Confirm each finding against the rules above before
  145. changing code.
  146. Do not claim an optimization compiles until `cargo check` passes. If no toolchain is
  147. available, say that the code was not compiled.
  148. ## Diff Guard
  149. Shortcuts rarely happen when the task is "fix this borrow error". They happen when a
  150. borrow error interrupts other work and the quickest way back is a `.clone()`. The guard
  151. lists only the workarounds **you added** in the current change, so it stays quiet on
  152. existing code.
  153. Run it from inside the git repository before reporting the task as done:
  154. ```
  155. python <skill folder>/scripts/ownership_guard.py
  156. ```
  157. Use `python3` where `python` is not available. It flags new `.clone()`, `.to_owned()`,
  158. `.to_vec()`, `Rc<RefCell<_>>`, `Arc<Mutex<_>>`, `'static`, `Box::leak`, `unsafe`, and
  159. boxed collections. `Rc::clone(&x)` and `Arc::clone(&x)` are not flagged.
  160. For every finding, do one of two things:
  161. - Fix it using the checklist above.
  162. - Keep it and add a specific justification on the same line or the line above:
  163. `// ownership: worker thread needs its own copy`. The reason must say why a borrow
  164. or a move does not work here. Never add a vague comment just to silence the guard.
  165. If a hook already ran the guard after your edit, treat its output the same way.
  166. ## Anti-Patterns to Refuse
  167. - Adding `.clone()` at every error site until the code compiles.
  168. - Wrapping values in `Rc<RefCell<_>>` to escape the borrow checker.
  169. - Using `unsafe` to bypass borrow rules.
  170. - Changing a lifetime to `'static` or leaking memory (`Box::leak`) to fix a lifetime error.
  171. ## References
  172. - `references/error-codes.md`: borrow checker error codes, the design question behind
  173. each, and fixes that avoid copying. Read when a compiler error is present.
  174. - `references/patterns.md`: closures, threads and async tasks, iterators, conditional
  175. borrow returns, `Cow`, graphs and arenas. Read when the code uses any of these.
  176. - `examples/`: compilable before/after programs for clones, `Box`, borrow conflicts,
  177. and the advanced patterns.
  178. - `scripts/audit.ps1`, `scripts/audit.sh`: Clippy with the full ownership lint set.
  179. - `scripts/ownership_guard.py`: lists ownership workarounds added in the current diff.
README.md · README · 252 lines
  1. # rust-ownership-optimizer
  2. [![CI](https://github.com/ichbinrather/rust-ownership-optimizer/actions/workflows/ci.yml/badge.svg)](https://github.com/ichbinrather/rust-ownership-optimizer/actions/workflows/ci.yml)
  3. [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
  4. A skill for AI coding agents that work on Rust. It stops them from reaching for
  5. `.clone()`, `Box`, `Rc<RefCell<_>>` or `'static` whenever the borrow checker complains,
  6. and makes them fix the ownership instead.
  7. Works with Claude Code, Codex CLI, Cursor, GitHub Copilot, Gemini CLI, OpenCode, and
  8. anything else that reads `SKILL.md` or `AGENTS.md`.
  9. <p align="center">
  10. <img src="assets/demo.svg" alt="An agent fixing E0382: without the skill it clones the value, with the skill it borrows it" width="760">
  11. </p>
  12. ## Why
  13. Ask an agent to fix `error[E0382]: borrow of moved value` and a common answer is:
  14. ```rust
  15. print_report(report.clone());
  16. archive(report);
  17. ```
  18. It compiles, and it copies the whole report on every call. `print_report` only reads
  19. its argument, so the right fix is a borrow:
  20. ```rust
  21. fn print_report(report: &Report) { /* ... */ }
  22. print_report(&report);
  23. archive(report);
  24. ```
  25. The skill gives the agent a short procedure for this kind of decision: work out who
  26. should own the data, map the compiler error to a design question, go through a
  27. checklist (clones, boxes, borrow conflicts, allocations, lifetimes, smart pointers),
  28. and confirm with `cargo check` and Clippy. If the same error survives three attempts,
  29. it rethinks the data layout instead of adding another workaround.
  30. ## Install
  31. ### Windows
  32. ```powershell
  33. git clone https://github.com/ichbinrather/rust-ownership-optimizer.git
  34. cd rust-ownership-optimizer
  35. powershell -ExecutionPolicy Bypass -File .\install.ps1
  36. ```
  37. ### macOS / Linux
  38. ```bash
  39. git clone https://github.com/ichbinrather/rust-ownership-optimizer.git
  40. cd rust-ownership-optimizer
  41. ./install.sh
  42. ```
  43. The script looks for the config folders of the supported agents (`.claude`, `.codex`,
  44. `.cursor`, ...) in your home directory and copies the skill into each one it finds.
  45. Restart the agent afterwards.
  46. Options:
  47. - `-Link` / `--link`: link to the clone instead of copying it, so `git pull` updates
  48. the skill. On Windows this creates a directory junction, which does not need admin
  49. rights.
  50. - `-All` / `--all`: also install for agents whose folder does not exist yet.
  51. - `-Force` / `--force`: overwrite an existing install.
  52. If you have Node.js, `npx skills add ichbinrather/rust-ownership-optimizer` works too.
  53. ### Installing by hand
  54. Copy the repository into the agent's skills folder under the name
  55. `rust-ownership-optimizer`, so that `SKILL.md` ends up directly inside it.
  56. | Agent | Skills folder |
  57. |-------|---------------|
  58. | Claude Code | `~/.claude/skills` |
  59. | Codex CLI | `~/.codex/skills` or `~/.agents/skills` |
  60. | OpenCode | `~/.config/opencode/skills` |
  61. | Cursor | `~/.cursor/skills` |
  62. | Gemini CLI | `~/.gemini/skills` |
  63. | GitHub Copilot | `~/.copilot/skills` |
  64. On Windows, `~` is `%USERPROFILE%`. These paths have moved between agent versions
  65. before, so check your agent's docs if the skill does not show up.
  66. To use it in a single project, put it in `.claude/skills/` inside the repository and
  67. copy `AGENTS.md` to the project root. Agents without skill support can use the rules
  68. in `AGENTS.md` directly: paste them into `.github/copilot-instructions.md`,
  69. `.cursor/rules/`, `GEMINI.md`, `.windsurf/rules/`, or `.clinerules/`.
  70. ### Checking that it loaded
  71. Restart the agent and ask which skills it has, or call it by name
  72. (`/rust-ownership-optimizer` in Claude Code, `$rust-ownership-optimizer` in Codex). On a
  73. Rust project, ask it to review a file for unnecessary clones. Findings come back like
  74. this:
  75. ```text
  76. [clone] src/report.rs:42: report cloned for a read-only call -> take &Report
  77. [box] src/shapes.rs:10: Box<dyn Shape> parameter only borrowed -> &dyn Shape
  78. ```
  79. ### Updating and removing
  80. With a linked install, `git pull` is enough. With a copied install, pull and run the
  81. installer again with `-Force` / `--force`.
  82. To remove it, delete `rust-ownership-optimizer` from the agent's skills folder. If you
  83. installed with `-Link` on Windows, remove the junction with `cmd /c rmdir <path>`.
  84. In Windows PowerShell 5.1, `Remove-Item -Recurse` on a junction can delete the files in
  85. your clone as well.
  86. If PowerShell says that running scripts is disabled, use the
  87. `-ExecutionPolicy Bypass` form shown above. It applies to that single run only.
  88. ## What it covers
  89. - Clones that only exist to satisfy the compiler: read-only arguments, comparisons,
  90. loops, inspecting an `Option`.
  91. - `Box` that adds indirection without a reason: `Box<Vec<T>>`, boxed locals,
  92. `Box<dyn Trait>` parameters where a reference would do.
  93. - Borrow checker errors E0382, E0499, E0502, E0505, E0506, E0507, E0515, E0597, E0716,
  94. E0106 and E0596, with fixes that do not copy data
  95. ([references/error-codes.md](references/error-codes.md)).
  96. - Closures, `thread::scope`, `Arc` for spawned tasks, iterator adapters, the "get or
  97. insert" case the current borrow checker rejects, `Cow`, and index-based graphs
  98. ([references/patterns.md](references/patterns.md)).
  99. - Escape hatches it will not use: `'static` to silence a lifetime error, `Box::leak`,
  100. `unsafe`, and `Rc<RefCell<_>>` everywhere.
  101. The full instructions are in [SKILL.md](SKILL.md).
  102. ## Diff guard
  103. Strong models rarely take the `.clone()` shortcut when the task is "fix this borrow
  104. error". It happens when a borrow error shows up in the middle of some other task and
  105. the clone is the fastest way back. `scripts/ownership_guard.py` catches that case: it
  106. looks only at the lines added in the current change and lists new `.clone()`,
  107. `.to_owned()`, `.to_vec()`, `Rc<RefCell<_>>`, `Arc<Mutex<_>>`, `'static`, `Box::leak`,
  108. `unsafe`, and boxed collections. Existing code is ignored.
  109. ```text
  110. $ python scripts/ownership_guard.py
  111. src/game.rs:41: [clone] new .clone(): borrow, move on last use, or share with Arc/Rc instead
  112. for p in self.players.clone() {
  113. 1 new ownership workaround(s). For each one, either fix it or add a specific
  114. justification on the same line or the line above, e.g. `// ownership: snapshot must outlive the lock`.
  115. ```
  116. A finding goes away when the line is fixed or carries a reason:
  117. `// ownership: worker thread needs its own copy`. `Rc::clone(&x)` and `Arc::clone(&x)`
  118. are never flagged. It needs Python 3.8+ and git, and works on Windows, macOS and Linux.
  119. The skill tells the agent to run the guard before it finishes. You can also run it
  120. automatically in three places.
  121. **After every edit in Claude Code.** Add a hook to `~/.claude/settings.json` (or
  122. `.claude/settings.json` in a project). The guard's output is sent back to the agent,
  123. which then fixes or justifies each finding:
  124. ```json
  125. {
  126. "hooks": {
  127. "PostToolUse": [
  128. {
  129. "matcher": "Edit|MultiEdit|Write",
  130. "hooks": [
  131. {
  132. "type": "command",
  133. "command": "python3 \"$HOME/.claude/skills/rust-ownership-optimizer/scripts/ownership_guard.py\" --hook claude"
  134. }
  135. ]
  136. }
  137. ]
  138. }
  139. }
  140. ```
  141. Use `python` instead of `python3` if that is the name on your system, and adjust the
  142. path if you installed the skill elsewhere.
  143. **Before every commit.** Save this as `.git/hooks/pre-commit` in your project (on macOS
  144. and Linux, also run `chmod +x .git/hooks/pre-commit`):
  145. ```sh
  146. #!/bin/sh
  147. python3 path/to/ownership_guard.py --staged
  148. ```
  149. **In pull requests.** Copy `ownership_guard.py` into your repository and add a step to
  150. your GitHub Actions workflow:
  151. ```yaml
  152. - uses: actions/checkout@v4
  153. with:
  154. fetch-depth: 0
  155. - run: python3 scripts/ownership_guard.py --base origin/${{ github.base_ref }}
  156. if: github.event_name == 'pull_request'
  157. ```
  158. ## Examples
  159. Each rule has a before/after program you can run:
  160. ```text
  161. cargo run --example unnecessary_clone
  162. cargo run --example unnecessary_box
  163. cargo run --example borrow_conflicts
  164. cargo run --example advanced_patterns
  165. ```
  166. To audit your own project with the same Clippy lints the skill uses, run
  167. `scripts/audit.ps1` (Windows) or `scripts/audit.sh` from the project root.
  168. ## Evals
  169. [evals/](evals/) has six small programs with mistakes an agent should catch, together
  170. with the prompt to give it and what counts as a pass. One of them pushes the agent to
  171. "just make it compile".
  172. Results so far, all on Claude Sonnet:
  173. - When fixing a borrow error **is** the task, Sonnet rarely takes a shortcut with or
  174. without the skill: 29/30 clean runs without it, 30/30 with it.
  175. - When the borrow problem shows up **inside a feature task**, it is different. Asked to
  176. add a game `tick()` that logs and heals players while iterating them, all three runs
  177. without the skill cloned every player's name on every tick to get past the borrow
  178. checker. None of the six runs with the skill did.
  179. That is a small sample and one model. Smaller models are not tested yet. Details, the
  180. projects, and every patch are in [evals/RESULTS.md](evals/RESULTS.md).
  181. If you run the evals with another agent or model, please post the results in an issue.
  182. ## Contributing
  183. The most useful report is a case where the agent still did the wrong thing with the
  184. skill installed. There is an issue template for that. For new rules, examples or evals,
  185. see [CONTRIBUTING.md](CONTRIBUTING.md).
  186. For broader Rust coverage (error handling, async, domain-specific advice), have a look
  187. at [actionbook/rust-skills](https://github.com/actionbook/rust-skills).
  188. ## License
  189. MIT

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.