用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-rust --skill ownership-borrowing命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | ownership-borrowing |
| description | Master Rust's ownership, borrowing, and lifetime system |
| sasmp_version | 1.3.0 |
| bonded_agent | rust-fundamentals-agent |
| bond_type | PRIMARY_BOND |
| version | 1.0.0 |
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<i32>) -> 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