一键导入
ownership-borrowing
Master Rust's ownership, borrowing, and lifetime system. Use when working with move semantics, references, lifetimes, or memory safety patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Master Rust's ownership, borrowing, and lifetime system. Use when working with move semantics, references, lifetimes, or memory safety patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create or update a release version entry in version.md. Use when drafting a new version, cutting a release, or when the user asks to create or update release notes.
Application overview for frename. Use when: orienting to the project for the first time, deciding which crate or module to touch, understanding what the app does end-to-end, looking up where a concept lives (tags, files, ordering, colors), or understanding keyboard shortcuts and the tag/file lifecycle.
Core development guide for frename-core. Use when: adding or changing traits (StoredTagStore, AppStateStore), modifying TagList logic, working with OrderedCollection, adding Tag fields, changing FileSnapshot/FileTagger, writing core tests, or adding database schema/migrations.
Image preview implementation guide for frename. Use when: adding or changing the media_viewer feature, working with FileKind classification, changing how FolderWorkspace opens files, adding JPEG or HEIC/HEIF decoding, understanding the no-unload path for images, or moving video_player into media_viewer.
UI + core combination guide for frename. Use when: wiring a new feature that spans both UI state and core data, deciding where logic lives (core vs UI), connecting a new message to a core operation, changing how file workspace or folder workspace coordinates with TagList or AppDatabase, or understanding the data flow between a user action and disk write.
Undo/redo implementation guide for frename. Use when: implementing the undo infrastructure in frename-core, adding a new undoable command, wiring Ctrl+Z/Ctrl+Y in the UI, or understanding how History, UndoContext, and commands interact.
| name | ownership-borrowing |
| description | Master Rust's ownership, borrowing, and lifetime system. Use when working with move semantics, references, lifetimes, or memory safety patterns. |
Master Rust's revolutionary memory safety system without garbage collection.
// Rule 1: Each value has exactly ONE owner
let s1 = String::from("hello"); // s1 owns this String
// Rule 2: Only ONE owner at a time
let s2 = s1; // Ownership MOVES to s2
// println!("{}", s1); // ERROR: s1 no longer valid
// Rule 3: Value is dropped when owner goes out of scope
{
let s3 = String::from("temporary");
} // s3 dropped here, memory freed
fn main() {
let s = String::from("hello");
// Immutable borrow
let len = calculate_length(&s);
println!("{} has length {}", s, len);
// Mutable borrow
let mut s = String::from("hello");
change(&mut s);
println!("{}", s); // "hello, world"
}
fn calculate_length(s: &String) -> usize {
s.len()
}
fn change(s: &mut String) {
s.push_str(", world");
}
// Explicit lifetime annotation
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() { x } else { y }
}
// Struct with lifetime
struct Excerpt<'a> {
part: &'a str,
}
let s1 = String::from("hello");
let s2 = s1.clone(); // Deep copy
println!("{} {}", s1, s2); // Both valid
fn process(s: String) -> String {
// Do something with s
s // Return ownership
}
fn analyze(data: &Vec<Data>) -> Summary {
// Only read, don't own
Summary::from(data)
}
// Problem
let s = String::from("hello");
let s2 = s;
println!("{}", s); // ERROR
// Solution 1: Clone
let s2 = s.clone();
// Solution 2: Borrow
let s2 = &s;
// Problem
let s = String::from("hello");
change(&mut s); // ERROR: s is not mut
// Solution: Declare as mutable
let mut s = String::from("hello");
change(&mut s); // OK