
Rust
- 41 installs
- 19 repo stars
- Updated January 20, 2026
- miles990/claude-software-skills
Helps with ai & agent building tasks.
About
rust is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- rust
- AI & Agent Building
- AI-coding skill
Rust by the numbers
- 41 all-time installs (skills.sh)
- +1 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #8,148 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/miles990/claude-software-skills --skill rustAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 41 |
|---|---|
| repo stars | ★ 19 |
| Last updated | January 20, 2026 |
| Repository | miles990/claude-software-skills ↗ |
What it does
Helps with ai & agent building tasks.
Files
Rust
Overview
Rust programming patterns including ownership, lifetimes, traits, and async programming.
---
Ownership and Borrowing
Basic Ownership
fn main() {
// Ownership transfer (move)
let s1 = String::from("hello");
let s2 = s1; // s1 is moved to s2
// println!("{}", s1); // Error: s1 is no longer valid
// Clone for deep copy
let s3 = String::from("hello");
let s4 = s3.clone();
println!("{} {}", s3, s4); // Both valid
// Copy types (stack-only data)
let x = 5;
let y = x; // Copy, not move
println!("{} {}", x, y); // Both valid
}
// Ownership and functions
fn takes_ownership(s: String) {
println!("{}", s);
} // s is dropped here
fn makes_copy(x: i32) {
println!("{}", x);
} // x goes out of scope, nothing special
fn gives_ownership() -> String {
String::from("hello")
}
fn takes_and_gives_back(s: String) -> String {
s
}Borrowing
// Immutable borrow
fn calculate_length(s: &String) -> usize {
s.len()
} // s goes out of scope but doesn't drop the value
// Mutable borrow
fn append_world(s: &mut String) {
s.push_str(" world");
}
fn main() {
let s = String::from("hello");
// Multiple immutable borrows OK
let r1 = &s;
let r2 = &s;
println!("{} {}", r1, r2);
// Mutable borrow (only one at a time)
let mut s2 = String::from("hello");
let r3 = &mut s2;
r3.push_str(" world");
println!("{}", r3);
// Cannot have mutable and immutable at same time
let mut s3 = String::from("hello");
let r4 = &s3;
// let r5 = &mut s3; // Error!
println!("{}", r4);
}Lifetimes
// Explicit lifetime annotations
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() { x } else { y }
}
// Struct with lifetime
struct Excerpt<'a> {
part: &'a str,
}
impl<'a> Excerpt<'a> {
fn level(&self) -> i32 {
3
}
fn announce_and_return(&self, announcement: &str) -> &str {
println!("Attention: {}", announcement);
self.part
}
}
// Multiple lifetimes
fn complex<'a, 'b>(x: &'a str, y: &'b str) -> &'a str
where
'b: 'a, // 'b outlives 'a
{
x
}
// Static lifetime
fn static_string() -> &'static str {
"I live forever"
}---
Structs and Enums
Structs
#[derive(Debug, Clone, PartialEq)]
struct User {
id: u64,
email: String,
name: String,
active: bool,
}
impl User {
// Associated function (constructor)
fn new(email: String, name: String) -> Self {
Self {
id: generate_id(),
email,
name,
active: true,
}
}
// Method
fn deactivate(&mut self) {
self.active = false;
}
// Method returning reference
fn email(&self) -> &str {
&self.email
}
}
// Tuple struct
struct Color(u8, u8, u8);
struct Point(f64, f64, f64);
// Unit struct
struct AlwaysEqual;Enums
// Basic enum
enum Direction {
North,
South,
East,
West,
}
// Enum with data
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
ChangeColor(u8, u8, u8),
}
impl Message {
fn process(&self) {
match self {
Message::Quit => println!("Quit"),
Message::Move { x, y } => println!("Move to ({}, {})", x, y),
Message::Write(text) => println!("Write: {}", text),
Message::ChangeColor(r, g, b) => println!("Color: ({}, {}, {})", r, g, b),
}
}
}
// Result and Option
fn divide(a: f64, b: f64) -> Result<f64, String> {
if b == 0.0 {
Err(String::from("Division by zero"))
} else {
Ok(a / b)
}
}
fn find_user(id: u64) -> Option<User> {
// ...
None
}---
Traits
// Trait definition
trait Summary {
fn summarize(&self) -> String;
// Default implementation
fn summarize_author(&self) -> String {
String::from("(unknown author)")
}
}
// Implement trait
impl Summary for User {
fn summarize(&self) -> String {
format!("{} ({})", self.name, self.email)
}
}
// Trait bounds
fn notify<T: Summary>(item: &T) {
println!("Breaking news: {}", item.summarize());
}
// Multiple trait bounds
fn notify_multiple<T: Summary + Clone>(item: &T) {
let cloned = item.clone();
println!("{}", cloned.summarize());
}
// where clause
fn some_function<T, U>(t: &T, u: &U) -> i32
where
T: Summary + Clone,
U: Clone + std::fmt::Debug,
{
// ...
0
}
// Return trait
fn create_summarizable() -> impl Summary {
User::new(
String::from("test@example.com"),
String::from("Test"),
)
}
// Trait objects (dynamic dispatch)
fn process_summaries(items: &[&dyn Summary]) {
for item in items {
println!("{}", item.summarize());
}
}---
Error Handling
use std::fs::File;
use std::io::{self, Read};
use thiserror::Error;
// Custom error with thiserror
#[derive(Error, Debug)]
pub enum AppError {
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Parse error: {0}")]
Parse(#[from] std::num::ParseIntError),
#[error("Not found: {0}")]
NotFound(String),
#[error("Validation error: {field} - {message}")]
Validation { field: String, message: String },
}
// Using Result
fn read_file(path: &str) -> Result<String, AppError> {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
Ok(contents)
}
// ? operator chains
fn read_username_from_file() -> Result<String, io::Error> {
let mut username = String::new();
File::open("username.txt")?.read_to_string(&mut username)?;
Ok(username)
}
// Option handling
fn find_and_process(id: u64) -> Option<String> {
let user = find_user(id)?;
let data = process_user(&user)?;
Some(data)
}
// Combinators
fn get_user_email(id: u64) -> Option<String> {
find_user(id)
.map(|user| user.email)
.filter(|email| !email.is_empty())
}
fn parse_and_double(s: &str) -> Result<i32, std::num::ParseIntError> {
s.parse::<i32>().map(|n| n * 2)
}---
Async Programming
use tokio;
use futures::future;
// 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)
}
// Concurrent execution
async fn fetch_all(urls: Vec<&str>) -> Vec<Result<String, reqwest::Error>> {
let futures: Vec<_> = urls.iter().map(|url| fetch_data(url)).collect();
future::join_all(futures).await
}
// Select (race)
use tokio::select;
use tokio::time::{sleep, Duration};
async fn fetch_with_timeout(url: &str) -> Result<String, &'static str> {
select! {
result = fetch_data(url) => result.map_err(|_| "fetch error"),
_ = sleep(Duration::from_secs(5)) => Err("timeout"),
}
}
// Spawn tasks
async fn process_items(items: Vec<String>) {
let handles: Vec<_> = items
.into_iter()
.map(|item| {
tokio::spawn(async move {
process_item(&item).await
})
})
.collect();
for handle in handles {
if let Err(e) = handle.await {
eprintln!("Task failed: {}", e);
}
}
}
// Streams
use futures::stream::{self, StreamExt};
async fn process_stream() {
let numbers = stream::iter(vec![1, 2, 3, 4, 5]);
numbers
.map(|n| async move { n * 2 })
.buffer_unordered(3)
.for_each(|n| async move {
println!("{}", n);
})
.await;
}
// Channels
use tokio::sync::mpsc;
async fn channel_example() {
let (tx, mut rx) = mpsc::channel(32);
tokio::spawn(async move {
for i in 0..10 {
tx.send(i).await.unwrap();
}
});
while let Some(value) = rx.recv().await {
println!("Received: {}", value);
}
}---
Collections and Iterators
use std::collections::{HashMap, HashSet, VecDeque};
// Vec operations
let mut vec = vec![1, 2, 3];
vec.push(4);
vec.extend([5, 6, 7]);
let first = vec.first();
let last = vec.pop();
// HashMap
let mut map: HashMap<String, i32> = HashMap::new();
map.insert(String::from("key"), 42);
map.entry(String::from("key2")).or_insert(0);
// Iterator methods
let numbers = vec![1, 2, 3, 4, 5];
let doubled: Vec<_> = numbers.iter().map(|x| x * 2).collect();
let sum: i32 = numbers.iter().sum();
let evens: Vec<_> = numbers.iter().filter(|x| *x % 2 == 0).collect();
let found = numbers.iter().find(|&&x| x > 3);
let all_positive = numbers.iter().all(|x| *x > 0);
// Chaining
let result: i32 = numbers
.iter()
.filter(|x| *x % 2 == 0)
.map(|x| x * 2)
.sum();
// Custom iterator
struct Counter {
count: u32,
max: u32,
}
impl Iterator for Counter {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.count < self.max {
self.count += 1;
Some(self.count)
} else {
None
}
}
}---
Smart Pointers
use std::rc::Rc;
use std::cell::RefCell;
use std::sync::{Arc, Mutex};
// Box - heap allocation
let boxed = Box::new(5);
let list = Box::new(Node {
value: 1,
next: Some(Box::new(Node { value: 2, next: None })),
});
// Rc - reference counting
let a = Rc::new(5);
let b = Rc::clone(&a);
let c = Rc::clone(&a);
println!("count: {}", Rc::strong_count(&a)); // 3
// RefCell - interior mutability
let cell = RefCell::new(5);
*cell.borrow_mut() += 1;
println!("{}", cell.borrow()); // 6
// Rc<RefCell<T>> - shared mutable state
let shared = Rc::new(RefCell::new(vec![1, 2, 3]));
let shared2 = Rc::clone(&shared);
shared.borrow_mut().push(4);
shared2.borrow_mut().push(5);
// Arc - thread-safe Rc
let arc = Arc::new(5);
let arc2 = Arc::clone(&arc);
// Arc<Mutex<T>> - shared mutable state across threads
let counter = Arc::new(Mutex::new(0));
let handles: Vec<_> = (0..10)
.map(|_| {
let counter = Arc::clone(&counter);
std::thread::spawn(move || {
let mut num = counter.lock().unwrap();
*num += 1;
})
})
.collect();
for handle in handles {
handle.join().unwrap();
}---
Related Skills
- [[system-design]] - Systems programming
- [[desktop-apps]] - Tauri applications
- [[performance-optimization]] - Low-level optimization
# Rust Cargo.toml Template
# Usage: Copy to project root and update package details
[package]
name = "myproject"
version = "0.1.0"
edition = "2021"
authors = ["Your Name <you@example.com>"]
description = "A Rust project"
license = "MIT"
repository = "https://github.com/yourorg/myproject"
readme = "README.md"
keywords = ["rust", "example"]
categories = ["command-line-utilities"]
# See more keys at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
# ===========================================
# Async Runtime (choose one)
# ===========================================
tokio = { version = "1.35", features = ["full"] }
# async-std = { version = "1.12", features = ["attributes"] }
# ===========================================
# Web Framework (choose one)
# ===========================================
# axum = "0.7"
# actix-web = "4"
# rocket = "0.5"
# warp = "0.3"
# ===========================================
# Serialization
# ===========================================
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
# toml = "0.8"
# serde_yaml = "0.9"
# ===========================================
# Database
# ===========================================
# sqlx = { version = "0.7", features = ["runtime-tokio", "postgres", "migrate"] }
# diesel = { version = "2.1", features = ["postgres"] }
# sea-orm = { version = "0.12", features = ["runtime-tokio-native-tls", "sqlx-postgres"] }
# ===========================================
# Error Handling
# ===========================================
thiserror = "1.0"
anyhow = "1.0"
# miette = { version = "7.0", features = ["fancy"] }
# color-eyre = "0.6"
# ===========================================
# Logging
# ===========================================
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
# log = "0.4"
# env_logger = "0.10"
# ===========================================
# Configuration
# ===========================================
# config = "0.14"
# dotenvy = "0.15"
# ===========================================
# CLI
# ===========================================
# clap = { version = "4.4", features = ["derive"] }
# dialoguer = "0.11"
# indicatif = "0.17"
# ===========================================
# HTTP Client
# ===========================================
# reqwest = { version = "0.11", features = ["json"] }
# ===========================================
# Utilities
# ===========================================
# chrono = { version = "0.4", features = ["serde"] }
# uuid = { version = "1.6", features = ["v4", "serde"] }
# regex = "1.10"
# once_cell = "1.19"
# parking_lot = "0.12"
[dev-dependencies]
# Testing
# tokio-test = "0.4"
# mockall = "0.12"
# wiremock = "0.5"
# fake = { version = "2.9", features = ["derive"] }
# rstest = "0.18"
# criterion = "0.5"
[profile.release]
lto = true
codegen-units = 1
panic = "abort"
strip = true
[profile.dev]
# Faster compile times during development
opt-level = 0
[profile.dev.package."*"]
# Optimize dependencies even in dev
opt-level = 2
# ===========================================
# Workspace (for monorepo)
# ===========================================
# [workspace]
# members = [
# "crates/*",
# ]
# resolver = "2"
# ===========================================
# Binary targets
# ===========================================
[[bin]]
name = "myproject"
path = "src/main.rs"
# ===========================================
# Library target
# ===========================================
# [lib]
# name = "myproject"
# path = "src/lib.rs"
# ===========================================
# Features
# ===========================================
[features]
default = []
# full = ["feature-a", "feature-b"]
# feature-a = []
# feature-b = ["dep:optional-dep"]
# ===========================================
# Build dependencies
# ===========================================
# [build-dependencies]
# built = "0.7"
Rust Templates
Configuration templates for Rust projects.
Files
| Template | Purpose |
|---|---|
Cargo.toml | Package manifest with common dependencies |
Usage
Initialize Project
# Create new project
cargo new myproject
cd myproject
# Or use template Cargo.toml
cp templates/Cargo.toml ./Cargo.toml
# Update package name and dependencies
# Build
cargo buildCommon Commands
# Development
cargo run # Run binary
cargo watch -x run # Auto-reload (requires cargo-watch)
cargo check # Fast type checking
# Build
cargo build # Debug build
cargo build --release # Release build
# Testing
cargo test # Run tests
cargo test -- --nocapture # Show println output
cargo test test_name # Run specific test
# Quality
cargo fmt # Format code
cargo clippy # Linter
cargo doc --open # Generate docsProject Structure
myproject/
├── Cargo.toml
├── Cargo.lock
├── src/
│ ├── main.rs # Binary entry
│ ├── lib.rs # Library entry
│ └── ...
├── tests/ # Integration tests
├── benches/ # Benchmarks
└── examples/ # Example codeRecommended Crates
Web Frameworks
| Crate | Description |
|---|---|
axum | Ergonomic, modular (Tokio ecosystem) |
actix-web | High performance |
rocket | Developer-friendly |
warp | Composable filters |
Async Runtimes
| Crate | Description |
|---|---|
tokio | Most popular, full-featured |
async-std | Std-like API |
Database
| Crate | Description |
|---|---|
sqlx | Async, compile-time checked SQL |
diesel | Type-safe ORM |
sea-orm | Async ORM |
Error Handling
| Crate | Description |
|---|---|
thiserror | Custom error types |
anyhow | Application errors |
miette | Fancy diagnostics |
Profile Optimization
# Fast compile, fast binary
[profile.release]
lto = true # Link-time optimization
codegen-units = 1 # Single codegen unit
panic = "abort" # Smaller binary
strip = true # Strip symbols
# Fast compile in dev
[profile.dev.package."*"]
opt-level = 2 # Optimize dependenciesUseful Dev Tools
# Install tools
cargo install cargo-watch # Auto-rebuild
cargo install cargo-edit # cargo add/rm
cargo install cargo-audit # Security audit
cargo install cargo-outdated # Check updates
cargo install cargo-expand # Macro expansion
cargo install cargo-flamegraph # Profiling
# Usage
cargo watch -x test # Auto-test
cargo add serde --features derive
cargo audit # Check vulnerabilities
cargo outdated # Show outdated depsFeature Flags
[features]
default = ["json"]
json = ["dep:serde_json"]
full = ["json", "yaml", "toml"]
yaml = ["dep:serde_yaml"]
toml = ["dep:toml"]# Build with features
cargo build --features "json yaml"
cargo build --all-features
cargo build --no-default-featuresRelated skills
AI & Agent Buildingagents