Back to Skills

rust-ownership-system

verified

Use when Rust's ownership system including ownership rules, borrowing, lifetimes, and memory safety. Use when working with Rust memory management.

View on GitHub

Marketplace

han

TheBushidoCollective/han

Plugin

jutsu-rust

Technique

Repository

TheBushidoCollective/han
60stars

jutsu/jutsu-rust/skills/rust-ownership-system/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-rust/skills/rust-ownership-system/SKILL.md -a claude-code --skill rust-ownership-system

Installation paths:

Claude
.claude/skills/rust-ownership-system/
Powered by add-skill CLI

Instructions

# Rust Ownership System

Master Rust's unique ownership system that provides memory safety without
garbage collection through compile-time checks.

## Ownership Rules

**Three fundamental ownership rules:**

1. Each value in Rust has a variable that's its owner
2. There can only be one owner at a time
3. When the owner goes out of scope, the value is dropped

```rust
fn ownership_basics() {
    // s owns the String
    let s = String::from("hello");

    // Ownership moved to s2
    let s2 = s;

    // Error: s no longer owns the value
    // println!("{}", s);

    println!("{}", s2); // OK
} // s2 dropped here, memory freed
```

## Move Semantics

**Ownership transfer (move):**

```rust
fn move_semantics() {
    let s1 = String::from("hello");

    // Ownership moved to function
    takes_ownership(s1);

    // Error: s1 no longer valid
    // println!("{}", s1);
}

fn takes_ownership(s: String) {
    println!("{}", s);
} // s dropped here

// Return ownership from function
fn gives_ownership() -> String {
    String::from("hello")
}

fn main() {
    let s = gives_ownership();
    println!("{}", s);
}
```

**Copy trait for stack types:**

```rust
fn copy_types() {
    // Types implementing Copy are duplicated, not moved
    let x = 5;
    let y = x; // x copied to y

    println!("x: {}, y: {}", x, y); // Both valid

    // Copy types: integers, floats, bool, char, tuples of Copy types
    let tuple = (1, 2.5, true);
    let tuple2 = tuple;
    println!("{:?} {:?}", tuple, tuple2); // Both valid
}
```

## Borrowing

**Immutable borrowing (references):**

```rust
fn immutable_borrow() {
    let s1 = String::from("hello");

    // Borrow s1 (immutable reference)
    let len = calculate_length(&s1);

    println!("Length of '{}' is {}", s1, len); // s1 still valid
}

fn calculate_length(s: &String) -> usize {
    s.len()
} // s goes out of scope, but doesn't drop the value

// Multiple immutable borrows allowed
fn multiple_immutable_borrows() {
    let s = String::fr

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
10966 chars