igmarin/rust-core-skills · Archived

ownership-borrowing

Borrow before clone. Accept &[T]/&str. Arc vs Rc. Interior mutability last.

First seen Aug 21, 2026

Installation

$ npx skills add igmarin/rust-core-skills --skill ownership-borrowing

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from igmarin/rust-core-skills.

npx skills add igmarin/rust-core-skills

Browse all from igmarin/rust-core-skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

License LICENSE
Default branch main
Open issues 0
Status Archived

Skill metadata

Parsed from SKILL.md frontmatter.

Version1.0.0
LicenseMIT
More metadata
version
1.0.0
user-invocable
true

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,162 B
  • docs SUMMARY.md 177 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 2 installs

SKILL.md

Ownership and borrowing

Goal

No allocation that a borrow would cover. Shared mutability only when the type system requires it.

Inputs / outputs

  • In: a function or type that owns or shares data
  • Out: API that takes the least ownership it needs

Reads / writes

  • Read: the function and its callers
  • Write: none unless a playbook opened the task

Approval

None to drop clones. Stop for approval before adding Arc, Rc, Mutex, RwLock, or RefCell.

RULES — no exceptions

  1. Prefer &T / &mut T over .clone()
  2. Accept &[T] not &Vec<T>; &str not &String
  3. Cow<'_, T> only when you sometimes own
  4. Arc<T> across threads; Rc<T> single-thread only
  5. RefCell / Mutex / RwLock last; document why
  6. Copy for tiny, obviously copyable types; otherwise explicit Clone
  7. Move large values; Box if the move itself is the cost
  8. Elide lifetimes until the compiler asks

Example

// ❌
fn count_words(text: &String) -> usize {
    text.clone().split_whitespace().count()
}

// ✅
fn count_words(text: &str) -> usize {
    text.split_whitespace().count()
}

Clone is justified when storing, sending 'static to a thread, or the type is Copy.

Steps

  1. Grep the touched fn for .clone(
  2. If the clone is not stored or sent, borrow
  3. Widen params to slices/str

Validation

cargo test on the crate (or cargo test <test_name> -- --exact if a test is already red). Diff should drop clones or justify each remainder in one comment.

Pitfalls

❌ ✅
data.clone() to call a reader pass &data
Mutex for a single-thread cache RefCell or, better, owned local
Lifetime soup elide; name only 'src / 'a when needed

Integration

Predecessor: rust-essentials. Successor: type-driven-design. Do not hold a lock across .await.