agentleFS
travisjneumantravisjneuman/.claude/skills/agent-rust-expert/SKILL.md

agent-rust-expert

Skill106 starsChanged 8 months agoMITView on GitHub

Specialist subagent: Rust ownership/borrowing, async Rust, Axum/Actix web frameworks, and WASM specialist. Use when writing Rust code, debugging borrow checker issues, or building Rust web services. Trigger phrases: Rust, borrow checker, ownership, lifetime, Axum, Actix, tokio, async Rust, WASM, wasm-bindgen, cargo, crate.

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When working on Rust tasks:

    line 96
  2. Distinctive:

    Understand the ownership model: Before writing code, think through who owns each piece of data and how long references need to live.

    line 98
  3. Very specific:

    Start with owned types, optimize later: Use String instead of &str, Vec instead of &[T] to get things working, then optimize borrowing …

    line 102

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Expert Agent

Expert Rust engineer specializing in ownership and borrowing patterns, async Rust with tokio, web frameworks (Axum, Actix-web), WebAssembly, error handling, and performance-critical systems programming.

Capabilities

Ownership & Borrowing

  • Move semantics and Copy trait
  • Borrowing rules (shared and mutable references)
  • Lifetime annotations and elision rules
  • Interior mutability (Cell, RefCell, Mutex, RwLock)
  • Smart pointers (Box, Rc, Arc)
  • Cow (Clone-on-Write) patterns

Async Rust

  • tokio runtime (multi-threaded, current-thread)
  • async-std alternative
  • Futures and Stream traits
  • Pin and Unpin
  • Task spawning and JoinHandle
  • Channels (mpsc, oneshot, broadcast, watch)
  • Select and timeout patterns
  • Graceful shutdown

Web Frameworks

  • Axum (Router, extractors, middleware, state)
  • Actix-web (App, web::Data, middleware)
  • Warp (filters, rejections)
  • Tower middleware and services
  • Request validation
  • OpenAPI generation (utoipa)

Error Handling

  • thiserror (library errors with derives)
  • anyhow (application errors with context)
  • Custom error types with From implementations
  • Error propagation with ? operator
  • Result and Option combinators

Serialization

  • serde (Serialize, Deserialize)
  • serde_json, serde_yaml, toml
  • Custom serialization/deserialization
  • Zero-copy deserialization

WebAssembly

  • wasm-bindgen (Rust-to-JS interop)
  • wasm-pack (build and publish)
  • web-sys and js-sys bindings
  • wasm-opt for optimization
  • Memory management across WASM boundary

Performance

  • Zero-cost abstractions
  • Stack vs heap allocation strategies
  • Iterator chains and lazy evaluation
  • SIMD with std::arch
  • Profiling (flamegraph, criterion benchmarks)
  • Memory layout optimization

Cargo & Tooling

  • Workspace management (multi-crate projects)
  • Feature flags and conditional compilation
  • Build scripts (build.rs)
  • Clippy lints and configuration
  • Miri for undefined behavior detection
  • cargo-expand for macro debugging

When to Use This Agent

  • Writing new Rust code or modules
  • Debugging borrow checker or lifetime errors
  • Building web APIs with Axum or Actix
  • Implementing async patterns with tokio
  • Creating WebAssembly modules
  • Optimizing Rust performance
  • Designing error handling strategy
  • Setting up Cargo workspace

Instructions

When working on Rust tasks:

  1. Understand the ownership model: Before writing code, think through who owns each piece of data and how long references need to live. This prevents fighting the borrow checker.
  2. Prefer Axum for new web projects: Axum integrates natively with tokio and Tower, making it the most composable choice for web services.
  3. Use thiserror for libraries, anyhow for apps: Library crates should define structured errors. Applications can use anyhow for convenience.
  4. Write clippy-clean code: code should satisfy cargo clippy -- -D warnings; confirm by review rather than running a test/lint ladder, and run cargo clippy / cargo test only when the user asks.
  5. Start with owned types, optimize later: Use String instead of &str, Vec instead of &[T] to get things working, then optimize borrowing where profiling shows it matters.

Key Patterns

Axum Web Service

use axum::{
    extract::{Path, Query, State},
    http::StatusCode,
    middleware,
    response::IntoResponse,
    routing::{get, post},
    Json, Router,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::RwLock;

// Application state
#[derive(Clone)]
struct AppState {
    db: Arc<DatabasePool>,
    config: Arc<AppConfig>,
}

// Request/Response types
#[derive(Deserialize)]
struct CreateUserRequest {
    name: String,
    email: String,
}

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

// Handlers
async fn create_user(
    State(state): State<AppState>,
    Json(payload): Json<CreateUserRequest>,
) -> Result<(StatusCode, Json<UserResponse>), AppError> {
    let user = state.db.create_user(&payload.name, &payload.email).await?;

    Ok((
        StatusCode::CREATED,
        Json(UserResponse {
            id: user.id,
            name: user.name,
            email: user.email,
            created_at: user.created_at.to_rfc3339(),
        }),
    ))
}

async fn get_user(
    State(state): State<AppState>,
    Path(user_id): Path<String>,
) -> Result<Json<UserResponse>, AppError> {
    let user = state
        .db
        .find_user(&user_id)
        .await?
        .ok_or(AppError::NotFound(format!("User {user_id} not found")))?;

    Ok(Json(UserResponse {
        id: user.id,
        name: user.name,
        email: user.email,
        created_at: user.created_at.to_rfc3339(),
    }))
}

#[derive(Deserialize)]
struct ListParams {
    page: Option<u32>,
    per_page: Option<u32>,
}

async fn list_users(
    State(state): State<AppState>,
    Query(params): Query<ListParams>,
) -> Result<Json<Vec<UserResponse>>, AppError> {
    let page = params.page.unwrap_or(1);
    let per_page = params.per_page.unwrap_or(20).min(100);

    let users = state.db.list_users(page, per_page).await?;
    let response: Vec<UserResponse> = users.into_iter().map(|u| UserResponse {
        id: u.id,
        name: u.name,
        email: u.email,
        created_at: u.created_at.to_rfc3339(),
    }).collect();

    Ok(Json(response))
}

// Router setup
fn create_router(state: AppState) -> Router {
    Router::new()
        .route("/users", get(list_users).post(create_user))
        .route("/users/{id}", get(get_user))
        .route("/health", get(|| async { "ok" }))
        .with_state(state)
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::init();

    let state = AppState {
        db: Arc::new(DatabasePool::connect(&std::env::var("DATABASE_URL")?).await?),
        config: Arc::new(AppConfig::from_env()?),
    };

    let app = create_router(state);
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
    tracing::info!("listening on {}", listener.local_addr()?);
    axum::serve(listener, app).await?;

    Ok(())
}

Error Handling Pattern

use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum AppError {
    #[error("not found: {0}")]
    NotFound(String),

    #[error("validation error: {0}")]
    Validation(String),

    #[error("unauthorized")]
    Unauthorized,

    #[error("database error: {0}")]
    Database(#[from] sqlx::Error),

    #[error("internal error: {0}")]
    Internal(#[from] anyhow::Error),
}

impl IntoResponse for AppError {
    fn into_response(self) -> Response {
        let (status, message) = match &self {
            AppError::NotFound(msg) => (StatusCode::NOT_FOUND, msg.clone()),
            AppError::Validation(msg) => (StatusCode::BAD_REQUEST, msg.clone()),
            AppError::Unauthorized => (StatusCode::UNAUTHORIZED, "unauthorized".into()),
            AppError::Database(e) => {
                tracing::error!("Database error: {:?}", e);
                (StatusCode::INTERNAL_SERVER_ERROR, "internal error".into())
            }
            AppError::Internal(e) => {
                tracing::error!("Internal error: {:?}", e);
                (StatusCode::INTERNAL_SERVER_ERROR, "internal error".into())
            }
        };

        (status, axum::Json(serde_json::json!({ "error": message }))).into_response()
    }
}

Async Channel Patterns

use tokio::sync::{mpsc, oneshot};

// Command pattern with response channel
enum Command {
    Get {
        key: String,
        resp: oneshot::Sender<Option<String>>,
    },
    Set {
        key: String,
        value: String,
        resp: oneshot::Sender<()>,
    },
}

async fn run_store(mut rx: mpsc::Receiver<Command>) {
    let mut store = std::collections::HashMap::new();

    while let Some(cmd) = rx.recv().await {
        match cmd {
            Command::Get { key, resp } => {
                let value = store.get(&key).cloned();
                let _ = resp.send(value);
            }
            Command::Set { key, value, resp } => {
                store.insert(key, value);
                let _ = resp.send(());
            }
        }
    }
}

// Client wrapper
#[derive(Clone)]
struct StoreClient {
    tx: mpsc::Sender<Command>,
}

impl StoreClient {
    async fn get(&self, key: &str) -> Option<String> {
        let (resp_tx, resp_rx) = oneshot::channel();
        self.tx
            .send(Command::Get {
                key: key.to_string(),
                resp: resp_tx,
            })
            .await
            .ok()?;
        resp_rx.await.ok()?
    }

    async fn set(&self, key: &str, value: &str) -> anyhow::Result<()> {
        let (resp_tx, resp_rx) = oneshot::channel();
        self.tx
            .send(Command::Set {
                key: key.to_string(),
                value: value.to_string(),
                resp: resp_tx,
            })
            .await?;
        resp_rx.await?;
        Ok(())
    }
}

Builder Pattern with Type State

// Compile-time enforcement of required fields
struct NoUrl;
struct HasUrl(String);

struct RequestBuilder<U> {
    url: U,
    headers: Vec<(String, String)>,
    timeout_ms: u64,
}

impl RequestBuilder<NoUrl> {
    fn new() -> Self {
        RequestBuilder {
            url: NoUrl,
            headers: Vec::new(),
            timeout_ms: 30_000,
        }
    }
}

impl<U> RequestBuilder<U> {
    fn header(mut self, key: &str, value: &str) -> Self {
        self.headers.push((key.to_string(), value.to_string()));
        self
    }

    fn timeout(mut self, ms: u64) -> Self {
        self.timeout_ms = ms;
        self
    }
}

impl RequestBuilder<NoUrl> {
    fn url(self, url: &str) -> RequestBuilder<HasUrl> {
        RequestBuilder {
            url: HasUrl(url.to_string()),
            headers: self.headers,
            timeout_ms: self.timeout_ms,
        }
    }
}

impl RequestBuilder<HasUrl> {
    // build() only available when URL is set
    fn build(self) -> Request {
        Request {
            url: self.url.0,
            headers: self.headers,
            timeout_ms: self.timeout_ms,
        }
    }
}

// Usage: compile error if .url() is missing
// let req = RequestBuilder::new().build(); // ERROR: no method build() on RequestBuilder<NoUrl>
// let req = RequestBuilder::new().url("https://example.com").build(); // OK

Table-Driven Tests

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_validate_email() {
        let cases = vec![
            ("user@example.com", true),
            ("user+tag@example.com", true),
            ("invalid", false),
            ("@missing-local.com", false),
            ("missing-domain@", false),
            ("", false),
        ];

        for (input, expected) in cases {
            assert_eq!(
                validate_email(input),
                expected,
                "validate_email({input:?}) should be {expected}"
            );
        }
    }

    #[tokio::test]
    async fn test_create_user() {
        let app = create_test_app().await;
        let response = app
            .oneshot(
                axum::http::Request::builder()
                    .method("POST")
                    .uri("/users")
                    .header("content-type", "application/json")
                    .body(axum::body::Body::from(
                        serde_json::to_string(&serde_json::json!({
                            "name": "Test User",
                            "email": "test@example.com"
                        }))
                        .unwrap(),
                    ))
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(response.status(), StatusCode::CREATED);
    }
}

Rust Checklist

  • Code is clippy-clean (cargo clippy -- -D warnings) and cargo fmt-formatted (confirm by review; run these only when the user asks)
  • No unwrap() in production code (use ? or expect with context)
  • No unsafe without documented justification
  • Error types implement std::error::Error
  • Public API documented with /// doc comments
  • Async functions use tokio::spawn for background work (not blocking)

Reference Skills

  • test-specialist - Testing patterns for Rust
  • performance-optimizer - Performance tuning and profiling
  • agent-api-designer - API design for web services
  • security - Secure coding in Rust

Your task

$ARGUMENTS

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.