Rust Ownership

Ownership, borrowing, and lifetime expert. Handles compiler errors E0382, E0597, E0506, E0507, E0515, E0716, E0106 and provides systematic solutions for memory safety patterns.

49 stars 7 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add huiali/rust-skills --skill rust-ownership
Manual install
git clone --depth 1 https://github.com/huiali/rust-skills.git /tmp/rust-skills
mkdir -p ~/.claude/skills
cp -r /tmp/rust-skills/.codex/skills/rust-ownership ~/.claude/skills/rust-ownership

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

## Solution Patterns

### Pattern 1: Value Moved After Use

```rust
let s1 = String::from("hello");
let s2 = s1;
// println!("{}", s1); // Compile error!
```

**Root Cause**: Ownership transferred from `s1` to `s2`, `s1` is no longer valid.

**Solutions**:
- Need two copies → use `clone()`
- Only need to read → pass by reference `&s1`
- `s2` is temporary → consider redesign

### Pattern 2: Borrow Conflict

```rust
let mut s = String::from("hello");
let r1 = &s;
let r2 = &mut s; // Conflict!
// println!("{}", r1);
```

**Root Cause**: Immutable and mutable borrows coexist.

**Solutions**:
- Ensure mutable borrow completes before creating new borrows
- Restructure code organization

### Pattern 3: Lifetime Mismatch

```rust
fn longest<'a>(s1: &'a str, s2: &'a str) -> &'a str {
    if s1.len() > s2.len() { s1 } else { s2 }
}
```

**Root Cause**: Return value lifetime must be tied to one of the inputs.

**Key Solutions**:
1. Clarify each reference's lifetime
2. Use named lifetimes to express relationships
3. Prefer returning owned types

## Workflow

### Step 1: Who Owns the Data?

| Situation | Owner |
|-----------|-------|
| Function parameter | Caller owns |
| Function-local variable | Function owns (destroyed on return) |
| Struct field | Struct instance owns |
| `Arc<T>` | Multiple shared owners |

### Step 2: Is Borrowing Appropriate?

| Operation | Borrow Type | Notes |
|-----------|-------------|-------|
| Read-only | `&T` | Multiple can coexist |
Read the full skill on GitHub

Details

Skill name
rust-ownership
Path
.codex/skills/rust-ownership/SKILL.md
License
MIT
Repo updated
9 February 2026

FAQ

What does the Rust Ownership skill do?

Ownership, borrowing, and lifetime expert. Handles compiler errors E0382, E0597, E0506, E0507, E0515, E0716, E0106 and provides systematic solutions for memory safety patterns.

How do I install the Rust Ownership skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add huiali/rust-skills --skill rust-ownership. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Rust Ownership popular?

It lives in huiali/rust-skills, which has 49 GitHub stars and 7 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.