rust-ownership

Apply Rust ownership, borrowing, and lifetime patterns to code.

Updated Dec 13, 2025
One-click install
npx skills add https://github.com/imehr/vet --skill rust-ownership
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-ownership
Source: https://github.com/imehr/vet/tree/main/.claude/skills/rust-ownership
Command: npx skills add https://github.com/imehr/vet --skill rust-ownership

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps Rust developers reason about ownership, borrowing, and lifetimes to prevent common memory-safety mistakes and to write clearer, more efficient code.

Core Features & Use Cases

  • Pattern 1: Move vs Clone vs Copy — choose the right ownership model to control data movement and avoid unnecessary cloning.
  • Pattern 2: Borrowing Rules — manage immutable and mutable borrows to enable safe, concurrent access.
  • Pattern 3: Lifetimes in Functions and Structs — annotate and apply lifetimes to ensure references are valid across scopes.
  • Pattern 4: Smart Pointers for Shared Ownership — use Rc/Arc and RefCell/Mutex for interior mutability and thread-safe sharing.
  • Pattern 5: Avoiding Common Pitfalls — recognize when to clone, borrow, or restructure to prevent runtime or compile-time errors.
  • Use Case Example: Refactor a function to take a borrowed reference instead of transferring ownership to avoid unnecessary moves.

Quick Start

Install or ensure a Rust toolchain is available, then review the included examples and refactor your code by applying ownership, borrowing, and lifetime patterns. Run cargo build and tests to verify safety and correctness.

Frequently Asked Questions about rust-ownership

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Rust ownership errors when passing values between functions?

To fix Rust ownership errors, choose between moving, cloning, or borrowing values. This Skill provides patterns to manage data movement, such as refactoring functions to take borrowed references instead of transferring ownership unnecessarily.

What are the Rust borrowing rules for mutable and immutable references?

Rust borrowing rules enforce safe concurrent access by allowing either one mutable reference or multiple immutable references. This Skill helps you apply these borrowing patterns to manage memory safety without runtime overhead.

How do I use lifetimes in Rust structs and functions?

Lifetimes in Rust ensure references remain valid across scopes. This Skill provides patterns to annotate and apply lifetimes explicitly in functions and structs, preventing dangling references and compile-time safety errors.

When should I use Rc, Arc, RefCell, or Mutex for shared ownership in Rust?

Use Rc and RefCell for single-threaded shared ownership and interior mutability, while Arc and Mutex handle thread-safe sharing. This Skill provides patterns to implement these smart pointers for clear ownership models.

Do I need an existing Rust toolchain to apply these ownership and borrowing patterns?

Yes, you need an available Rust toolchain to build and test your code. You install the toolchain, apply the ownership, borrowing, and lifetime patterns to your project, and run cargo build to verify safety and correctness.

How to avoid common Rust memory-safety pitfalls and compile-time errors?

Avoid Rust memory-safety pitfalls by recognizing when to clone, borrow, or restructure your code. This Skill helps you identify common ownership and lifetime mistakes to prevent both runtime crashes and compile-time errors.