Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Design and review Rust ownership, borrowing, lifetimes, and interior mutability so data flow matches the domain model. Use when writing, refactoring, or reviewing Rust code that hits move, borrow checker, aliasing, Clone, Copy, Rc, Arc, RefCell, or lifetime problems.
.claude/skills/hashgraph-online-rust-ownership-borrowing/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 37% | 0% |
| case-11 | ✓→✓ | = Same ✓ | 4% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 6% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 21% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 1% | 0% |
Use this skill to make ownership shape match the program's data flow. Treat borrow-checker errors as design feedback: decide who owns each value, how long access must last, and whether mutation needs exclusivity or a different data shape.
borrow, or shared ownership.
helper functions, or earlier extraction so references end before mutation.
when the caller retains ownership. Clone only when duplicate ownership is intentional and the cost is acceptable.
ownership trees before reaching for Rc<RefCell<_>>.
Rc for single-threaded shared ownership and Arc for cross-threadshared ownership. Add Cell, RefCell, Mutex, or RwLock only when the mutation model is explicit.
compiler error that prompted the change.
T when the function consumes or stores the value.&T when the function only reads during the call.&mut T when the function must mutate and no other access should occur.lifetime.
&Vec<T>, &String, or &PathBuf when &[T], &str, or&Path expresses the needed capability.
data owned elsewhere. Owned fields are usually simpler.
Read references/borrow-patterns.md when resolving non-trivial compiler errors or reviewing a borrow-heavy patch.
Option::take, std::mem::take, or std::mem::replace to move a fieldout while leaving a valid value behind.
split_at_mut, get_mut, entry, drain, andretain instead of indexing patterns that create overlapping borrows.
Arc, Rc, and cheap IDs freely when that is the intendedownership handle; avoid cloning payloads to silence the compiler.
clearer or avoids hidden captures.
borrow checker.
Clone is deliberate and tested for semantic independence where relevant.compiler accepts the code.
Arc plus the right synchronization primitive;Rc and RefCell stay out of cross-thread paths.
Other measured skills in the registry, with their headline benchmark lift.