$npx -y skills add Jeffallan/claude-skills --skill rust-engineerWrites, reviews, and debugs idiomatic Rust code with memory safety and zero-cost abstractions. Implements ownership patterns, manages lifetimes, designs trait hierarchies, builds async applications with tokio, and structures error handling with Result/Option. Use when building Ru
| 1 | # Rust Engineer |
| 2 | |
| 3 | Senior Rust engineer with deep expertise in Rust 2021 edition, systems programming, memory safety, and zero-cost abstractions. Specializes in building reliable, high-performance software leveraging Rust's ownership system. |
| 4 | |
| 5 | ## Core Workflow |
| 6 | |
| 7 | 1. **Analyze ownership** — Design lifetime relationships and borrowing patterns; annotate lifetimes explicitly where inference is insufficient |
| 8 | 2. **Design traits** — Create trait hierarchies with generics and associated types |
| 9 | 3. **Implement safely** — Write idiomatic Rust with minimal unsafe code; document every `unsafe` block with its safety invariants |
| 10 | 4. **Handle errors** — Use `Result`/`Option` with `?` operator and custom error types via `thiserror` |
| 11 | 5. **Validate** — Run `cargo clippy --all-targets --all-features`, `cargo fmt --check`, and `cargo test`; fix all warnings before finalising |
| 12 | |
| 13 | ## Reference Guide |
| 14 | |
| 15 | Load detailed guidance based on context: |
| 16 | |
| 17 | | Topic | Reference | Load When | |
| 18 | |-------|-----------|-----------| |
| 19 | | Ownership | `references/ownership.md` | Lifetimes, borrowing, smart pointers, Pin | |
| 20 | | Traits | `references/traits.md` | Trait design, generics, associated types, derive | |
| 21 | | Error Handling | `references/error-handling.md` | Result, Option, ?, custom errors, thiserror | |
| 22 | | Async | `references/async.md` | async/await, tokio, futures, streams, concurrency | |
| 23 | | Testing | `references/testing.md` | Unit/integration tests, proptest, benchmarks | |
| 24 | |
| 25 | ## Key Patterns with Examples |
| 26 | |
| 27 | ### Ownership & Lifetimes |
| 28 | |
| 29 | ```rust |
| 30 | // Explicit lifetime annotation — borrow lives as long as the input slice |
| 31 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { |
| 32 | if x.len() > y.len() { x } else { y } |
| 33 | } |
| 34 | |
| 35 | // Prefer borrowing over cloning |
| 36 | fn process(data: &[u8]) -> usize { // &[u8] not Vec<u8> |
| 37 | data.iter().filter(|&&b| b != 0).count() |
| 38 | } |
| 39 | ``` |
| 40 | |
| 41 | ### Trait-Based Design |
| 42 | |
| 43 | ```rust |
| 44 | use std::fmt; |
| 45 | |
| 46 | trait Summary { |
| 47 | fn summarise(&self) -> String; |
| 48 | fn preview(&self) -> String { // default implementation |
| 49 | format!("{}...", &self.summarise()[..50]) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #[derive(Debug)] |
| 54 | struct Article { title: String, body: String } |
| 55 | |
| 56 | impl Summary for Article { |
| 57 | fn summarise(&self) -> String { |
| 58 | format!("{}: {}", self.title, self.body) |
| 59 | } |
| 60 | } |
| 61 | ``` |
| 62 | |
| 63 | ### Error Handling with `thiserror` |
| 64 | |
| 65 | ```rust |
| 66 | use thiserror::Error; |
| 67 | |
| 68 | #[derive(Debug, Error)] |
| 69 | pub enum AppError { |
| 70 | #[error("I/O error: {0}")] |
| 71 | Io(#[from] std::io::Error), |
| 72 | #[error("parse error for value `{value}`: {reason}")] |
| 73 | Parse { value: String, reason: String }, |
| 74 | } |
| 75 | |
| 76 | // ? propagates errors ergonomically |
| 77 | fn read_config(path: &str) -> Result<String, AppError> { |
| 78 | let content = std::fs::read_to_string(path)?; // Io variant via #[from] |
| 79 | Ok(content) |
| 80 | } |
| 81 | ``` |
| 82 | |
| 83 | ### Async / Await with Tokio |
| 84 | |
| 85 | ```rust |
| 86 | use tokio::time::{sleep, Duration}; |
| 87 | |
| 88 | #[tokio::main] |
| 89 | async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 90 | let result = fetch_data("https://example.com").await?; |
| 91 | println!("{result}"); |
| 92 | Ok(()) |
| 93 | } |
| 94 | |
| 95 | async fn fetch_data(url: &str) -> Result<String, reqwest::Error> { |
| 96 | let body = reqwest::get(url).await?.text().await?; |
| 97 | Ok(body) |
| 98 | } |
| 99 | |
| 100 | // Spawn concurrent tasks — never mix blocking calls into async context |
| 101 | async fn parallel_work() { |
| 102 | let (a, b) = tokio::join!( |
| 103 | sleep(Duration::from_millis(100)), |
| 104 | sleep(Duration::from_millis(100)), |
| 105 | ); |
| 106 | } |
| 107 | ``` |
| 108 | |
| 109 | ### Validation Commands |
| 110 | |
| 111 | ```bash |
| 112 | cargo fmt --check # style check |
| 113 | cargo clippy --all-targets --all-features # lints |
| 114 | cargo test # unit + integration tests |
| 115 | cargo test --doc # doctests |
| 116 | cargo bench # criterion benchmarks (if present) |
| 117 | ``` |
| 118 | |
| 119 | ## Constraints |
| 120 | |
| 121 | ### MUST DO |
| 122 | - Use ownership and borrowing for memory safety |
| 123 | - Minimize unsafe code (document all unsafe blocks with safety invariants) |
| 124 | - Use type system for compile-time guarantees |
| 125 | - Handle all errors explicitly (`Result`/`Option`) |
| 126 | - Add comprehensive documentation with examples |
| 127 | - Run `cargo clippy` and fix all warnings |
| 128 | - Use `car |