Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

rust-systems-programming

БесплатноБез исполняемых скриптовНе проверен

Complete guide for Rust systems programming including ownership, borrowing, concurrency, async programming, unsafe code, and performance optimization

manutejот manutej★ 64 звезды на GitHub27 установок в других каталогах

Об этом скилле

Rust Systems Programming

A comprehensive skill for building high-performance, memory-safe systems software using Rust. This skill covers ownership, borrowing, concurrency, async programming, unsafe code, FFI, and performance optimization for systems-level development.

When to Use This Skill

Use this skill when:

  • Building systems software requiring memory safety without garbage collection
  • Developing high-performance applications with zero-cost abstractions
  • Writing concurrent or parallel programs with data race prevention
  • Creating async/await applications for I/O-bound workloads (web servers, databases)
  • Working with low-level code, FFI, or hardware interfaces
  • Replacing C/C++ code with safer alternatives
  • Building command-line tools, network services, or embedded systems
  • Optimizing performance-critical sections of applications
  • Creating libraries that guarantee memory safety at compile time
  • Developing WebAssembly modules for near-native performance

Core Concepts

The Ownership Model

Rust's ownership system is the foundation of its memory safety guarantees:

Ownership Rules:

  1. Each value in Rust has exactly one owner
  2. When the owner goes out of scope, the value is dropped
  3. Ownership can be transferred (moved) to new owners

Move Semantics:

struct MyStruct { s: u32 }

fn main() {
    let mut x = MyStruct{ s: 5u32 };
    let y = x;  // Ownership moved from x to y
    // x.s = 6;  // ERROR: x is no longer valid
    // println!("{}", x.s);  // ERROR: cannot use x after move
}

When a type doesn't implement Copy, assignment moves ownership rather than copying. This prevents double-free errors and use-after-move bugs at compile time.

For Copy Types:

let x = 5;  // i32 implements Copy
let y = x;  // x is copied, not moved
println!("{}", x);  // OK: x is still valid

Borrowing and References

Borrowing allows temporary access to data without taking ownership:

Immutable Borrowing:

fn main() {
    let s1 = String::from("hello");

    let len = calculate_length(&s1);  // Borrow s1 immutably

    println!("The length of '{}' is {}.", s1, len);  // s1 still valid
}

fn calculate_length(s: &String) -> usize {
    s.len()  // Can read but not modify
}

Mutable Borrowing:

Rust enforces exclusive mutable access to prevent data races:

fn main() {
    let mut value = 3;
    let borrow = &mut value;  // Mutable borrow
    *borrow += 1;
    println!("{}", borrow);  // 4

    // value is accessible again after borrow ends
}

Borrowing Rules:

  • You can have either one mutable reference OR any number of immutable references
  • References must always be valid (no dangling pointers)
  • Mutable and immutable borrows cannot coexist

Common Borrowing Error:

fn main() {
    let mut value = 3;
    // Create a mutable borrow of `value`.
    let borrow = &mut value;
    let _sum = value + 1; // ERROR: cannot use `value` because
                          //        it was mutably borrowed
    println!("{}", borrow);
}

Lifetimes

Lifetimes ensure references are always valid:

fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() {
        x
    } else {
        y
    }
}

The 'a lifetime parameter tells the compiler that the returned reference will be valid as long as both input references are valid.

Ownership Patterns for Sharing

Rc (Reference Counted) for Single-threaded Shared Ownership:

use std::cell::RefCell;
use std::rc::Rc;

struct MyStruct { s: u32 }

fn main() {
    let mut x = Rc::new(RefCell::new(MyStruct{ s: 5u32 }));
    let y = x.clone();  // Increment reference count
    x.borrow_mut().s = 6;  // Interior mutability via RefCell
    println!("{}", x.borrow().s);
}

Rc<T> provides shared ownership with reference counting. RefCell<T> enables interior mutability, enforcing borrow rules at runtime rather than compile time.

Arc (Atomic Reference Counted) for Thread-safe Sharing:

use std::sync::Arc;
use std::thread;

struct FancyNum {
    num: u8,
}

fn main() {
    let fancy_ref1 = Arc::new(FancyNum { num: 5 });
    let fancy_ref2 = fancy_ref1.clone();

    let x = thread::spawn(move || {
        // `fancy_ref1` can be moved and has a `'static` lifetime
        println!("child thread: {}", fancy_ref1.num);
    });

    x.join().expect("child thread should finish");
    println!("main thread: {}", fancy_ref2.num);
}

Arc<T> is the thread-safe version of Rc<T>, using atomic operations for reference counting.

Box for Heap Allocation

Box<T>

Box<T> is an owning pointer that allocates T on the heap. Useful for:

  • Recursive types with known size
  • Large values that should not be copied on the stack
  • Trait objects with dynamic dispatch

Concurrency Patterns

Threads and Message Passing

Rust prevents data races at compile time through its ownership system:

use std::thread;
use st
Полный SKILL.md на GitHub

Установить rust-systems-programming в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

EXAMPLES.mdREADME.md

FAQ

Что делает скилл rust-systems-programming?

Complete guide for Rust systems programming including ownership, borrowing, concurrency, async programming, unsafe code, and performance optimization

Как установить скилл rust-systems-programming?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл rust-systems-programming запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить rust-systems-programming с