2.5k
GitHub Stars
2
Bundled Files
2 months ago
Catalog Refreshed
3 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill openclaw/skills --skill rust-patterns- _meta.json282 B
- SKILL.md6.6 KB
Overview
This skill provides production-ready Rust patterns for 2026 focused on ownership, async with Tokio, Axum web services, SQLx and other DB libraries, error handling, CLI tooling, WASM, and PyO3 Python bindings. It targets Rust Edition 2024 and summarizes concrete mental models, anti-patterns, and recipes you can apply directly in projects. The content is practical, opinionated, and oriented toward maintainable, high-performance systems.
How this skill works
The skill distills common patterns into short examples and decision guides: ownership and borrowing analogies, when to use thiserror vs anyhow, Tokio runtime idioms (spawn, select!, spawn_blocking), Axum routing and shared state, and compile-time checked SQLx usage. It also covers concurrency primitives (Arc, Mutex, RwLock, channels, Rayon), Clap v4 for CLIs, PyO3 bindings for Python extensions, and recommended anti-patterns to avoid.
When to use it
- Designing concurrent or async Rust services where avoiding blocking and correct ownership are critical
- Building HTTP APIs with Axum and shared application state
- Choosing between SQLx, Diesel, or SeaORM based on async needs and safety guarantees
- Creating high-performance native extensions for Python with PyO3 or building WASM modules
- Authoring CLI tools with Clap derive API and clear error handling strategies
Best practices
- Prefer references and clear ownership transfers over excessive cloning; document ownership intent in APIs
- Use thiserror for library error types (matchable variants) and anyhow for application-level errors with context
- Avoid sync blocking inside async functions; use tokio::fs or tokio::task::spawn_blocking for heavy I/O
- Favor channels for message-passing patterns; reserve Arc<Mutex> for simple shared state cases
- Enable SQLx compile-time checks during CI and pick the ORM that matches team expectations (raw SQL vs typed query builder)
Example use cases
- Implementing a multi-threaded Axum web server with shared AppState and SQLx-backed handlers
- Converting a CPU-bound Python hotspot to a PyO3 native extension built with maturin
- Building a resilient CLI tool with Clap v4, structured errors via thiserror, and clear exit codes
- Refactoring an async codebase to remove blocking I/O, applying spawn_blocking and Tokio select! for timeouts
- Using Rayon to speed up batch data processing while keeping IO on async tasks
FAQ
Use thiserror for libraries so callers can match error variants. Use anyhow in applications to capture error chains and add context for user-facing diagnostics.
How do I avoid blocking the Tokio runtime?
Replace std::fs with tokio::fs for async I/O, offload heavy CPU or blocking work to tokio::task::spawn_blocking, and keep handlers async and non-blocking.