rust-ownership

Diagnose and fix Rust borrow-checker errors using ownership, borrowing, and lifetime rules.

3|Updated Aug 8, 2026
One-click install
npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-ownership-jose-polanco-oxte
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-ownership
Source: https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer/tree/main/.agents/skills/rust/sub-skills/rust-ownership
Command: npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-ownership-jose-polanco-oxte

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rust's borrow checker rejects code with cryptic errors like E0382, E0499, or E0597, and developers often reach for .clone() as a reflex instead of understanding the underlying ownership rule being violated. This Skill provides the mental model behind ownership, borrowing, and lifetimes, plus concrete fixes for each compiler error. ## Core Features & Use Cases - Error-to-fix mapping: A lookup table maps common borrow-checker errors (E0382, E0499, E0502, E0505, E0507, E0515, E0597, E0106) to their meaning and the first fix to try. - Signature and pointer decision guides: Decision tables for choosing T vs &T vs &mut T in function signatures, and for picking Box, Rc, RefCell, Cow, or Weak for sharing and mutation. - Resource lifecycle patterns: Covers RAII guards, scope guards with transaction rollback, and lazy initialization with OnceLock/LazyLock, including the let _ = guard-drop footgun. - Use Case: When the compiler rejects code with "cannot borrow as mutable more than once" (E0499), consult the guide to learn about non-lexical lifetimes, disjoint field borrows, and split_at_mut instead of cloning. ## Quick Start Ask the assistant to explain why your Rust code fails with a borrow-checker error and how to fix it without cloning.

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 borrow checker errors like E0382 or E0499?

E0382 (use of moved value) is usually fixed by borrowing with & instead of moving, or reordering so the move is the last use. E0499 (two mutable borrows) is fixed by shortening one borrow's scope via non-lexical lifetimes or splitting into disjoint fields.

Should I use Box, Rc, RefCell, or Cow in Rust?

Use Box for heap allocation, recursive types, or trait objects; Rc for multiple owners on one thread; RefCell for mutation through a shared reference; and Rc<RefCell<T>> for shared mutable data. Cow fits returns that are usually borrowed but occasionally owned.

When should a Rust function take T, &T, or &mut T?

Take &T when you only read the value, &mut T when you mutate it in place and the caller keeps it, and T when you store, consume, or move it into a thread or struct. Default to borrowing inputs and owning only when necessary.

Why does Rust say a borrowed value does not live long enough?

Error E0597 means a reference outlives the value it points to. Fix it by extending the owner's scope, hoisting the owner above the borrow, or storing the owned value instead of the reference in structs.

How do I lazily initialize a global value in Rust?

Use std::sync::LazyLock for a lazily computed static, or OnceLock with get_or_init for a struct field initialized on first use. Both are thread-safe and replace the older lazy_static crate since Rust 1.80.

When is cloning the right fix for a borrow error in Rust?

Cloning is appropriate for small Copy-like data, breaking self-referential tangles, or handing owned data to a thread. It is wrong when it merely hides a borrow that would have worked, which usually signals a design issue.