| name | maverick-rust-ownership |
| description | Rust ownership, borrowing, and lifetimes Use when this capability is needed. |
| metadata | {"author":"get2knowio"} |
Rust Ownership Skill
Ownership Rules
- Each value has exactly one owner
- When owner goes out of scope, value is dropped
- Values can be moved or borrowed
Borrowing Rules
- One mutable reference OR any number of immutable references
- References must always be valid
let s = String::from("hello");
let r1 = &s;
let r2 = &s;
let r3 = &mut s;
Lifetimes
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() { x } else { y }
}
Review Severity
- CRITICAL: Dangling references, use after move
- MAJOR: Unnecessary clones, incorrect lifetime annotations
- MINOR: Could use references instead of owned values
Converted and distributed by TomeVault — claim your Tome and manage your conversions.