本文へ移動
cccskills
無料GitHub で公開

rust-programming-expert

Expert-level skill for Rust programming (Rust 2024 / v1.88+). Covers memory safety, Grounded Permissions Model (R/W/O/F), async Axum 0.8/SQLx, CLI, and zero-cost optimization in English and Indonesian.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plugスター 115(GitHub 115 + cccskills 0)

実行スコア 未検証

インストール方法を見る

含まれるファイル(1)

  • SKILL.md15.5 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Rust Programming Expert (2024 Edition / v1.88+)

English | Bahasa Indonesia


<a name="english"></a>

English

Orchestration & Integration

Connects and orchestrates with domain skills:

  • Systems, Desktop & WASM: tauri-expert (desktop native IPC), wasm-edge-computing-expert, and ephemeral-wasm-sandbox-executor for safe in-memory sandboxing and edge execution.
  • Backend & APIs: api-design-expert (Axum 0.8 REST & tonic gRPC), database-orm-expert (async SQLx & SeaORM), and fullstack-expert for polyglot services.
  • Quality & Testing: autonomous-tdd-debugger, e2e-testing-expert, and anti-slop for executing cargo test, compile-time SQL verification, and zero-panic error handling (Result<T, E> without lazy .unwrap()).
  • Orchestration: brainstorming and zero-to-prod-orchestrator (Phase 4: Backend & APIs).

Description

Expert-level Rust development for building memory-safe, high-performance systems, APIs, CLI tools, and WebAssembly. Covers the Rust 2024 edition, the Grounded Permissions Model of Ownership (Brown University Framework), async/await with Tokio, Axum 0.8 web framework, SQLx for async database access, and modern Rust idioms.

Trigger Conditions

  • Writing systems-level code requiring memory safety and zero-cost abstractions.
  • Solving borrow-checker, lifetime, or aliasing conflicts using flow-sensitive permissions.
  • Building high-performance HTTP APIs with Axum 0.8.
  • Implementing async services with Tokio runtime.
  • Interacting with databases using SQLx or SeaORM.
  • Building CLI tools with Clap v4.
  • Compiling to WebAssembly (WASM) for browser or edge deployment.
  • Writing Rust for Tauri v2 desktop application backends.

1. The Grounded Ownership & Permissions Model (Brown University Framework)

Based on empirical cognitive research by Brown University's Cognitive Engineering Lab (OOPSLA 2023/2024: "A Grounded Conceptual Model for Ownership Types in Rust"), Rust's borrow checker evaluates programs through flow-sensitive permissions on paths ($\pi$):

Path (π) Permissions:
├── Read  (R): Permission to read or copy data from a path
├── Write (W): Permission to mutate data in-place
├── Own   (O): Permission to move data or drop the allocation
└── Flow  (F): Permission to return a reference or pass it out of scope

Permission Transitions Across Lifecycles:

OperationPath x (Lender)Reference y (Borrower)Dereference *y
let mut x = ...;Initialized: {R, W, O}——
let y = &x;Loses W, O ➔ {R}{R, O}{R}
let y = &mut x;Loses R, W, O ➔ {} (Quarantined){R, O}{R, W}
Last use of y (NLL)Restores {R, W, O}DroppedInactive

The 4 Grounded Strategies for Resolving Borrow-Check Errors:

  1. Copy vs Clone vs Borrow: Distinguish stack-only Copy types from heap types. Pass borrowed slices (&str, &[T]) rather than calling .clone() unless independent ownership is semantically required.
  2. Mutate In-Place vs Reassignment: Avoid passing and returning owned values (fn process(s: String) -> String) when passing &mut String preserves caller permissions without reallocation.
  3. Disjoint Splitting (split_at_mut): The compiler treats slice[0] and slice[1] as sharing the root path slice. Use safe abstractions like slice.split_at_mut(mid) to borrow distinct halves mutably in parallel.
  4. Controlled Interior Mutability:
    • Single-threaded: Cell<T> (for Copy types) or RefCell<T> (dynamic runtime borrow checks).
    • Multi-threaded: Arc<RwLock<T>> for read-heavy shared data, or Arc<Mutex<T>> for mutual exclusion.
// Practical Demonstration of Flow-Sensitive Permissions & Disjoint Borrowing
pub fn demonstrate_grounded_ownership() {
    // 1. Initial Path has {R, W, O}
    let mut numbers = vec![10, 20, 30, 40, 50];

    // 2. Disjoint Mutable Slicing (avoiding whole-collection borrow quarantine)
    let (left, right) = numbers.split_at_mut(2);
    // left: &mut [10, 20], right: &mut [30, 40, 50]
    left[0] += 5;
    right[0] *= 2;

    // 3. After last use of left/right, numbers restores {R, W, O}
    println!("Updated numbers: {:?}", numbers);

    // 4. Safe Thread-Safe Interior Mutability
    use std::sync::Arc;
    use tokio::sync::RwLock;

    let shared_state = Arc::new(RwLock::new(vec!["rust".to_string()]));
    let state_clone = Arc::clone(&shared_state);

    tokio::spawn(async move {
        let mut lock = state_clone.write().await;
        lock.push("permissions".to_string());
    });
}

2. Rust 2024 Edition Highlights

The Rust 2024 edition (stabilized in 1.85) introduces:

  • gen blocks: Generators for lazy sequence production.
  • Lifetime capture rules: More precise lifetime inference in impl Trait.
  • Unsafe extern blocks: Clearer unsafe boundary declarations.
  • if let chains: if let Some(x) = opt && x > 0 now works cleanly.
  • async fn in traits: Now stable — no more async-trait macro needed.

Async fn in Traits (Stable in Rust 2024)

// No longer need #[async_trait] macro!
trait DataStore {
    async fn get(&self, id: &str) -> Result<Data, Error>;
    async fn set(&self, id: &str, data: Data) -> Result<(), Error>;
}

impl DataStore for PostgresStore {
    async fn get(&self, id: &str) -> Result<Data, Error> {
        sqlx::query_as("SELECT * FROM data WHERE id = $1")
            .bind(id)
            .fetch_one(&self.pool)
            .await
            .map_err(Into::into)
    }
    async fn set(&self, id: &str, data: Data) -> Result<(), Error> {
        sqlx::query("INSERT INTO data (id, value) VALUES ($1, $2) ON CONFLICT (id) DO UPDATE SET value = $2")
            .bind(id)
            .bind(&data.value)
            .execute(&self.pool)
            .await?;
        Ok(())
    }
}

3. Axum 0.8 — HTTP API Framework

use axum::{
    extract::{Path, State},
    http::StatusCode,
    response::Json,
    routing::{get, post},
    Router,
};
use sqlx::PgPool;
use serde::{Deserialize, Serialize};

#[derive(Clone)]
struct AppState {
    db: PgPool,
}

#[derive(Serialize, Deserialize)]
struct User {
    id: String,
    name: String,
    email: String,
}

async fn get_user(
    Path(user_id): Path<String>,
    State(state): State<AppState>,
) -> Result<Json<User>, StatusCode> {
    let user = sqlx::query_as!(User, "SELECT * FROM users WHERE id = $1", user_id)
        .fetch_optional(&state.db)
        .await
        .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
        .ok_or(StatusCode::NOT_FOUND)?;

    Ok(Json(user))
}

#[tokio::main]
async fn main() {
    let db = PgPool::connect(&std::env::var("DATABASE_URL").unwrap())
        .await
        .expect("Failed to connect to database");

    let state = AppState { db };

    let app = Router::new()
        .route("/users/:id", get(get_user))
        .with_state(state);

    let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
    println!("Listening on :8080");
    axum::serve(listener, app).await.unwrap();
}

4. SQLx — Compile-Time Verified SQL

// Compile-time SQL checking (requires DATABASE_URL at build time)
let users = sqlx::query_as!(
    User,
    r#"SELECT id, name, email FROM users WHERE created_at > $1 ORDER BY created_at DESC LIMIT $2"#,
    since,
    limit as i64
)
.fetch_all(&pool)
.await?;

5. Error Handling — thiserror + anyhow

use thiserror::Error;

// Library errors: use thiserror for typed errors
#[derive(Debug, Error)]
pub enum AppError {
    #[error("User not found: {id}")]
    UserNotFound { id: String },
    #[error("Database error: {0}")]
    Database(#[from] sqlx::Error),
    #[error("Validation failed: {message}")]
    Validation { message: String },
}

// Application code: use anyhow for ergonomic error propagation
use anyhow::{Context, Result};

fn process() -> Result<()> {
    let config = load_config().context("Failed to load configuration")?;
    let db = connect_db(&config).context("Failed to connect to database")?;
    Ok(())
}

6. CLI Tools with Clap v4

use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(name = "myapp", version, about = "My CLI tool")]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Start the server
    Serve {
        #[arg(short, long, default_value = "8080")]
        port: u16,
    },
    /// Run migrations
    Migrate,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let cli = Cli::parse();
    match cli.command {
        Commands::Serve { port } => serve(port).await,
        Commands::Migrate => run_migrations().await,
    }
}

7. Performance Best Practices

  • Zero-cost abstractions: Use iterators (map, filter, collect) — compiled to the same code as hand-written loops.
  • Avoid unnecessary cloning: Use references (&T) and lifetimes where possible.
  • Arc<T> for shared state: Use Arc<Mutex<T>> or Arc<RwLock<T>> for shared mutable state across threads.
  • SIMD: Use std::simd (stable in 1.88) for data-parallel operations.
  • Profile before optimizing: Use cargo flamegraph or perf to find actual bottlenecks.

<a name="bahasa-indonesia"></a>

Bahasa Indonesia

Integrasi Orkestrasi

Terhubung dan mengorkestrasi bersama skill domain:

  • Sistem, Desktop & WASM: tauri-expert (IPC aplikasi desktop native), wasm-edge-computing-expert, dan ephemeral-wasm-sandbox-executor untuk eksekusi WASM efemeral dan komputasi edge.
  • Backend & API: api-design-expert (Axum 0.8 REST & tonic gRPC), database-orm-expert (async SQLx & SeaORM), dan fullstack-expert untuk arsitektur polyglot.
  • Kualitas & Pengujian: autonomous-tdd-debugger, e2e-testing-expert, dan anti-slop untuk eksekusi cargo test, verifikasi SQL saat kompilasi, dan penanganan error tanpa panic (Result<T, E> tanpa unwrap ceroboh).
  • Orkestrator Utama: brainstorming dan zero-to-prod-orchestrator (Fase 4: Backend & APIs).

Deskripsi

Pengembangan Rust tingkat ahli untuk membangun sistem, API, CLI tool, dan WebAssembly yang aman di memori dan berkinerja tinggi. Mencakup edisi Rust 2024, Model Konseptual Ownership & Permissions (Framework Brown University), async/await dengan Tokio, framework web Axum 0.8, SQLx untuk akses database async, dan idiom Rust modern.

Kondisi Pemicu

  • Menulis kode sistem yang membutuhkan keamanan memori dan zero-cost abstraction.
  • Memecahkan konflik borrow-checker, lifetime, atau aliasing menggunakan izin sensitif-alur (flow-sensitive permissions).
  • Membangun HTTP API berkinerja tinggi dengan Axum 0.8.
  • Mengimplementasikan layanan async dengan runtime Tokio.
  • Berinteraksi dengan database menggunakan SQLx atau SeaORM.
  • Membangun CLI tool dengan Clap v4.
  • Mengkompilasi ke WebAssembly (WASM) untuk browser atau edge.
  • Menulis backend Rust untuk aplikasi desktop Tauri v2.

1. Model Konseptual Ownership & Permissions (Framework Brown University)

Mengadopsi riset kognitif empiris dari Cognitive Engineering Lab Brown University (OOPSLA 2023/2024: "A Grounded Conceptual Model for Ownership Types in Rust"), sistem borrow checker Rust dievaluasi melalui izin sensitif-alur (flow-sensitive permissions) pada setiap path memori ($\pi$):

Izin Path (π):
├── Read  (R): Izin membaca atau menyalin data dari path
├── Write (W): Izin memutasi data langsung di tempat
├── Own   (O): Izin memindahkan (move) data atau menghapus alokasi (drop)
└── Flow  (F): Izin mengembalikan referensi atau meloloskannya ke luar scope

Transisi Izin Sepanjang Siklus Peminjaman:

OperasiPath x (Pemberi Pinjaman)Referensi y (Peminjam)Dereferensi *y
let mut x = ...;Terinisialisasi: {R, W, O}——
let y = &x;Kehilangan W, O ➔ {R}{R, O}{R}
let y = &mut x;Kehilangan R, W, O ➔ {} (Karantina total){R, O}{R, W}
Penggunaan akhir y (NLL)Mengembalikan {R, W, O}DihapusNonaktif

4 Strategi Menyelesaikan Error Borrow-Checker:

  1. Copy vs Clone vs Borrow: Bedakan tipe Copy (hanya di stack) dari tipe heap. Lewatkan referensi (&str, &[T]) alih-alih memanggil .clone() sembarangan kecuali transfer kepemilikan memang dibutuhkan.
  2. Mutasi di Tempat vs Reasigment: Hindari pola oper-kembali kepemilikan (fn proses(s: String) -> String) jika meminjam &mut String mempertahankan izin pemanggil tanpa alokasi ulang memori.
  3. Pemisahan Terputus (Disjoint Splitting): Kompiler memandang elemen array berbagi path induk yang sama. Gunakan abstraksi aman seperti slice.split_at_mut(mid) untuk memutasi dua bagian irisan secara terpisah.
  4. Interior Mutability Terkendali:
    • Single-thread: Gunakan Cell<T> atau RefCell<T> (pemeriksaan peminjaman dinamis saat runtime).
    • Multi-thread: Gunakan Arc<RwLock<T>> untuk beban dominan baca, atau Arc<Mutex<T>> untuk proteksi mutasi bersama.
// Contoh Nyata Penerapan Permissions & Disjoint Borrowing
pub fn demonstrasi_ownership_brown() {
    let mut angka = vec![10, 20, 30, 40, 50];

    // Pemisahan irisan mutabel terputus (mencegah karantina koleksi total)
    let (kiri, kanan) = angka.split_at_mut(2);
    kiri[0] += 5;
    kanan[0] *= 2;

    // Setelah scope peminjaman selesai (NLL), path angka memulihkan izin {R, W, O}
    println!("Angka terupdate: {:?}", angka);

    // Interior mutability aman multi-thread
    use std::sync::Arc;
    use tokio::sync::RwLock;

    let state_bersama = Arc::new(RwLock::new(vec!["rust".to_string()]));
    let clone_state = Arc::clone(&state_bersama);

    tokio::spawn(async move {
        let mut kunci = clone_state.write().await;
        kunci.push("permissions".to_string());
    });
}

2. Sorotan Edisi Rust 2024

  • async fn dalam trait: Kini stabil — tidak perlu lagi macro #[async_trait].
  • if let chains: if let Some(x) = opt && x > 0 kini berfungsi secara bersih.
  • gen blocks: Generator untuk produksi urutan yang malas.
  • Aturan lifetime capture: Inferensi lifetime yang lebih presisi di impl Trait.

3. Axum 0.8 — Framework HTTP API

Gunakan Axum untuk HTTP API yang idiomatis dan berkinerja tinggi dibangun di atas Tokio. Manfaatkan extractor (Path, State, Json, Query) untuk parameter handler yang type-safe.

4. SQLx — SQL Terverifikasi Waktu Kompilasi

SQLx memverifikasi query SQL Anda terhadap database nyata saat kompilasi — menghilangkan seluruh kelas bug runtime.

5. Penanganan Error — thiserror + anyhow

  • Gunakan thiserror untuk error bertipe di library code.
  • Gunakan anyhow untuk propagasi error yang ergonomis di application code.

6. CLI Tool dengan Clap v4

Clap v4 menggunakan derive macro untuk mendefinisikan antarmuka CLI secara deklaratif — perintah, subperintah, argumen, dan flag dengan parsing bawaan.

7. Praktik Terbaik Performa

  • Gunakan iterator (map, filter, collect) — dikompilasi setara dengan loop manual.
  • Hindari cloning yang tidak perlu — gunakan referensi dan lifetime.
  • Gunakan Arc<Mutex<T>> untuk state bersama yang dapat dimutasi di antara thread.
  • Profiling terlebih dahulu dengan cargo flamegraph sebelum mengoptimalkan.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

A2A agent protocol interoperability, Agent Cards, and MCP bridging / Protokol agen A2A, Agent Cards, dan integrasi MCP.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1152026年10月27日 更新

Expert guide for automated and manual Web Accessibility (a11y) testing — axe-core, Pa11y, Playwright a11y, screen reader testing, and WCAG 2.2 Level AA/AAA compliance / Panduan ahli pengujian aksesibilitas web.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1152026年10月27日 更新

Web accessibility testing with axe-core, Playwright, and WCAG 2.2 / Pengujian aksesibilitas web axe-core, Playwright, dan WCAG 2.2.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1152026年10月27日 更新

Model cascading & complexity-scored routing (Grok, Gemini, Claude) / Routing kaskade model & scoring kompleksitas (Grok, Gemini, Claude).

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1152026年10月27日 更新

Expert guide for intelligent model cascading and routing — complexity-scored task routing from Flash/Haiku to Sonnet/Opus/Astra, dynamic escalation with quality gates, 40-60% token cost reduction while maintaining output quality / Panduan ahli untuk kaskade dan routing model cerdas — routing tugas berbasis skor kompleksitas dari Flash/Haiku ke Sonnet/Opus/Astra, eskalasi dinamis dengan gerbang kualitas, pengurangan biaya token 40-60% dengan kualitas output terjaga.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1152026年10月27日 更新

Affective computing, emotion AI, and multimodal sentiment analysis / Komputasi afektif, AI emosional, dan analisis sentimen multimodal.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1152026年10月27日 更新

roedyrustam のスキルをすべて見る

このスキルの問題を報告する