rust
БесплатноБез исполняемых скриптовНе проверенRust systems programming language. Covers ownership, borrowing, lifetimes, async/await, error handling, and Cargo. Use for high-performance backend systems…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Rust Core Knowledge
Full Reference: See advanced.md for builder pattern, advanced traits, async patterns (join!/select!/spawn), custom errors with thiserror, and production configuration.
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:rustfor comprehensive documentation.
Ownership System
Rust's memory safety is guaranteed through its ownership system without a garbage collector.
The Three Ownership Rules
- Each value in Rust has an owner
- There can only be one owner at a time
- When the owner goes out of scope, the value will be dropped
Move Semantics (Heap Data)
fn main() {
let s1 = String::from("hello");
let s2 = s1; // s1 is MOVED to s2
// println!("{s1}"); // ERROR: s1 is no longer valid
println!("{s2}"); // OK: s2 owns the data
}
Copy Semantics (Stack Data)
fn main() {
let x = 5;
let y = x; // x is COPIED (not moved)
println!("x = {x}, y = {y}"); // Both valid
}
Types implementing Copy trait:
- All integer types (
u32,i64, etc.) - Boolean (
bool) - Floating-point types (
f64) - Character (
char) - Tuples of Copy types
Clone for Deep Copying
fn main() {
let s1 = String::from("hello");
let s2 = s1.clone(); // Explicit deep copy
println!("s1 = {s1}, s2 = {s2}"); // Both valid
}
Borrowing and References
Immutable References
fn main() {
let s1 = String::from("hello");
let len = calculate_length(&s1); // Borrow s1
println!("Length of '{s1}' is {len}"); // s1 still valid
}
fn calculate_length(s: &String) -> usize {
s.len()
} // s goes out of scope but doesn't drop data (just a reference)
Mutable References
fn main() {
let mut s = String::from("hello");
change(&mut s);
println!("{s}"); // Prints "hello, world"
}
fn change(s: &mut String) {
s.push_str(", world");
}
Borrowing Rules
- You can have either:
- One mutable reference, OR
- Any number of immutable references
- References must always be valid (no dangling references)
fn main() {
let mut s = String::from("hello");
let r1 = &s; // OK: first immutable borrow
let r2 = &s; // OK: second immutable borrow
println!("{r1} and {r2}");
// r1 and r2 no longer used after this point
let r3 = &mut s; // OK: mutable borrow (after immutables are done)
println!("{r3}");
}
Lifetimes
Lifetimes ensure references are valid for as long as they're used.
Lifetime Annotations
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() { x } else { y }
}
fn main() {
let string1 = String::from("long string");
let result;
{
let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str());
println!("Longest: {result}"); // Must use result here
}
// Can't use result here - string2 dropped
}
Lifetime Elision Rules
The compiler applies these rules automatically:
- Each input reference gets its own lifetime
- If exactly one input lifetime, output gets that lifetime
- If
&selfor&mut self, output getsself's lifetime
Static Lifetime
let s: &'static str = "I live forever";
Error Handling
Result Type
use std::fs::File;
use std::io::{self, Read};
fn read_username_from_file() -> Result<String, io::Error> {
let mut file = File::open("hello.txt")?; // ? propagates errors
let mut username = String::new();
file.read_to_string(&mut username)?;
Ok(username)
}
// Even shorter with fs::read_to_string
fn read_username_shortest() -> Result<String, io::Error> {
std::fs::read_to_string("hello.txt")
}
Option Type
fn find_user(id: u32) -> Option<User> {
users.iter().find(|u| u.id == id).cloned()
}
// Using Option
match find_user(42) {
Some(user) => println!("Found: {}", user.name),
None => println!("User not found"),
}
// Combinators
let name = find_user(42)
.map(|u| u.name)
.unwrap_or_else(|| "Anonymous".to_string());
Async/Await
Basic Async Function
async fn fetch_data(url: &str) -> Result<String, reqwest::Error> {
let response = reqwest::get(url).await?;
let body = response.text().await?;
Ok(body)
}
#[tokio::main]
async fn main() {
match fetch_data("https://api.example.com").await {
Ok(data) => println!("Got: {data}"),
Err(e) => eprintln!("Error: {e}"),
}
}
Structs and Implementations
Struct Definition
#[derive(Debug, Clone)]
pub struct User {
pub id: u64,
pub name: String,
pub email: String,
active: bool, // private field
}
impl User {
// Associated function (constructor)
pub fn new(id: u64, name: String, email: String) -> Self {
Self {
id,
name,
email,
active: true,
}
}
// Me
Установить rust в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditВложенные файлы
FAQ
Что делает скилл rust?
Rust systems programming language. Covers ownership, borrowing, lifetimes, async/await, error handling, and Cargo. Use for high-performance backend systems. USE WHEN: user mentions "rust", "ownership", "borrowing", "lifetimes", asks about "borrow checker", "cargo", "traits", "Result type", "async rust", "tokio" DO NOT USE FOR: reviewing existing Rust code - use `review/rust`, which covers the few defects rustc and clippy structurally cannot reach DO NOT USE FOR: Actix/Axum/Rocket frameworks - use framework-specific skills DO NOT USE FOR: WASM - use WebAssembly-specific skill DO NOT USE FOR: Tauri - use `tauri` skill instead
Как установить скилл rust?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл rust запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic