This skill provides expert-level Rust knowledge for building high-performance, memory-safe systems with Rust 1.75+ features, advanced async programming, and modern ecosystem practices.
What This Skill Provides
The Rust Pro skill equips agents with deep expertise in modern Rust development, focusing on advanced language features, async programming, and production-ready systems.Core Knowledge Areas
Modern Language Features
Rust 1.75+ features, const generics, GATs, advanced lifetime annotations
Ownership & Memory
Ownership rules, smart pointers, RAII patterns, zero-cost abstractions
Async Programming
Tokio runtime, async/await patterns, stream processing, concurrency
Type System Mastery
Advanced traits, GATs, phantom types, type-level programming
Performance
Zero-cost abstractions, SIMD, lock-free programming, profiling
Web Development
axum, warp, actix-web, hyper, HTTP/2-3 support, WebSocket
When This Skill Is Loaded
Agents load this skill when:- Building Rust services, libraries, or systems tooling
- Solving ownership, lifetime, or async design issues
- Optimizing performance with memory safety guarantees
- Implementing high-performance backend services
- Working with Tokio ecosystem (axum, tower, hyper)
- Creating memory-safe systems or embedded software
- Interfacing with C libraries via FFI
Use Cases
High-Performance Web Services
Building modern async web services with:- axum - Ergonomic, modular web framework built on tower
- tower - Middleware and service abstractions
- hyper - HTTP/2 and HTTP/3 support
- tokio - Async runtime for I/O operations
Modern Web Stack
axum + tower + tokio provides ergonomic, composable, high-performance web services with type-safe routing and middleware.
Async Programming with Tokio
Mastering async patterns:- Advanced async/await patterns
- Stream processing and async iterators
- Channel patterns (mpsc, broadcast, watch)
- Select patterns and concurrent task management
- Backpressure handling and flow control
Memory Management Excellence
Smart Pointers
- Box for heap allocation
- Rc/Arc for reference counting
- RefCell/Mutex for interior mutability
- Weak references
Zero-Cost Abstractions
- Memory layout optimization
- Phantom types and ZSTs
- Custom allocators
- RAII patterns
Systems Programming
- Low-level I/O - Memory mapping, direct hardware access
- Lock-free programming - Atomic operations, concurrent data structures
- FFI - Safe abstractions over C libraries
- Embedded - Cross-compilation, no_std environments
Type System Features
Advanced Type System:
- Generic Associated Types (GATs) - Higher-kinded type patterns
- Const Generics - Type-level numeric parameters
- Phantom Types - Zero-runtime-cost type safety
- Trait Bounds - Precise capability constraints
- Associated Types - Type-level function outputs
Key Principles
Ownership & Borrowing Mastery
Core Ownership Rules
- Each value has exactly one owner
- When the owner goes out of scope, value is dropped
- Borrowing rules: multiple immutable OR one mutable
- Lifetimes ensure references are always valid
Async Best Practices
Tokio Patterns:- Use async/await for I/O-bound operations
- Select! for concurrent waiting
- Channels for message passing
- Streams for async iteration
- Spawn tasks for parallelism
- Blocking operations in async contexts
- Too many small tasks (overhead)
- Forgetting to await futures
- Holding locks across await points
Performance Mindset
Zero-Cost Abstractions:Rust abstractions compile down to the same assembly as hand-written C code. Use high-level abstractions without runtime cost.When optimizing:
- Profile first (perf, flamegraph, criterion)
- Optimize hot paths only
- Use SIMD for data parallelism
- Consider cache-friendly data structures
- Leverage compile-time computation
Error Handling Excellence
Error Types
- thiserror - Derive error types
- anyhow - Application errors
- Custom error types for libraries
- Result and Option combinators
Best Practices
- Fail fast with ?
- Context preservation
- Typed errors for libraries
- Anyhow for applications
- Panic for unrecoverable errors
Related Skills
API Patterns
API design principles for Rust web services
Node.js Best Practices
Complementary backend runtime patterns
Python Patterns
Alternative backend development approaches
Which Agents Use This Skill
Backend Specialist
The Backend Specialist loads this skill for Rust-based backend development, high-performance services, and systems programming tasks.
Modern Web Frameworks
axum (Recommended)
Why axum?
- Built on tower (composable middleware)
- Type-safe routing with extractors
- Ergonomic error handling
- Excellent async support with tokio
- Growing ecosystem
Framework Comparison
| Framework | Best For | Complexity |
|---|---|---|
| axum | Modern APIs, microservices | Low-Medium |
| actix-web | High performance, mature | Medium |
| warp | Filter-based routing | Medium-High |
| rocket | Developer experience | Medium |
Testing & Quality
Testing Strategy
Unit Tests
Built-in
#[test] attribute, tests in same file or tests/ moduleIntegration Tests
Separate
tests/ directory, test public API as external crateProperty-Based
proptest, quickcheck for generative testing
Benchmarking
criterion.rs
Statistical benchmarking with:
- Precise measurements
- Statistical analysis
- Regression detection
- HTML report generation
Quality Tools
- Clippy - Lints and suggestions
- rustfmt - Code formatting
- cargo-audit - Security audits
- cargo-deny - Dependency policy enforcement
- tarpaulin - Code coverage
Unsafe Code & FFI
Safe Abstractions
Database Integration
Async Database Access
| Driver | Database | Features |
|---|---|---|
| sqlx | PostgreSQL, MySQL, SQLite | Compile-time checked queries |
| tokio-postgres | PostgreSQL | Pure Rust, async |
| diesel | PostgreSQL, MySQL, SQLite | ORM, sync |
| sea-orm | PostgreSQL, MySQL, SQLite | Async ORM |
Serialization
serde - The Standard
Universal serialization framework:
- JSON, YAML, TOML, MessagePack
- Derive macros for easy implementation
- Zero-copy deserialization
- Custom serialization logic
- Type-safe at compile time
Concurrency Patterns
Message Passing
mpsc
Multiple producers, single consumer channel
broadcast
Multiple producers, multiple consumers
watch
Single producer, multiple consumers (latest value)
Shared State
- Mutex - Mutual exclusion lock
- RwLock - Read-write lock (multiple readers, one writer)
- Arc - Atomic reference counting for shared ownership
- Atomic types - Lock-free primitives
Response Approach
Anti-Patterns to Avoid
Behavioral Traits
Expert Rust Developer Mindset:
- Leverages type system for compile-time correctness
- Prioritizes memory safety without sacrificing performance
- Uses zero-cost abstractions and avoids runtime overhead
- Implements explicit error handling with Result types
- Writes comprehensive tests including property-based
- Follows Rust idioms and community conventions
- Documents unsafe code blocks with safety invariants
- Optimizes for both correctness AND performance
- Embraces functional programming patterns
- Stays current with Rust evolution
