Awesome-omni-skill rust
Write production-quality Rust code following industry best practices and idiomatic patterns. Use for any Rust coding task including applications, libraries, refactoring, debugging, or code review — with particular expertise in cross-platform GUI development.
git clone https://github.com/diegosouzapw/awesome-omni-skill
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/development/rust" ~/.claude/skills/diegosouzapw-awesome-omni-skill-rust-41978a && rm -rf "$T"
skills/development/rust/SKILL.mdInstructions
1. Planning & Analysis
Before writing any code:
- Understand the full requirements and constraints
- Review the existing codebase for conventions, utilities, and patterns already in use
- Check for shared/common modules before creating new utilities
- Consider edge cases within reason unless the user specifically asks for more
- For GUI work: identify which platforms are targeted and any platform-specific constraints
2. Design Principles
Rust-Specific:
- Prefer borrowing over cloning; pass
not&str
,&String
not&Path
,&PathBuf
not&[T]&Vec<T> - Use enums, newtypes, and the type system to make illegal states unrepresentable
- Parse raw input into well-typed structures at the boundary, then pass typed data inward
- Leverage
,impl Into<T>
, and other conversion traits for ergonomic public APIsAsRef<T>
General:
- YAGNI: Implement only what is required; add complexity as the need arises
- KISS: Favor simplicity and clarity over cleverness
- DRY: Extract shared logic into common modules or helper functions
- Follow the repo's existing conventions over personal preference
3. Error Handling (anyhow required)
Use
as the primary error-handling crate. Do not introduce anyhow
thiserror, eyre, or other error libraries unless explicitly approved.
- All fallible functions return
anyhow::Result<T> - Attach context at every level with
or.context("message").with_context(|| format!(...)) - Propagate errors with
; never use?
orunwrap()
outside test codeexpect() - Use
oranyhow::anyhow!("message")
for ad-hoc errorsanyhow::bail!("message") - At the entrypoint: handle errors gracefully — print to
and exit with appropriate codestderr
4. Project Structure
Follow the structure established by the project. For new projects, use idiomatic Rust conventions:
Workspace projects:
- Place crates under a
directory; list them in rootcrates/Cargo.toml[workspace.members] - Shared utilities go in a common crate (e.g.,
orcrates/common/
)crates/shared/ - Each crate has a focused responsibility
Single-crate projects:
— thin entrypoint: init, parse args/config, call into app logic, handle exitsrc/main.rs
— public API surface; re-exports from submodulessrc/lib.rs
— domain types, config structs, enumssrc/models.rs
(or domain-named module) — core logicsrc/app.rs
General guidelines:
- Keep
thin — it orchestrates; logic lives in library codemain.rs - One module per concern; split files when they exceed ~300 lines
- Additional modules are fine when they keep things tidy and well-scoped
on config/model structs; add#[derive(Debug, Clone)]
,Copy
,PartialEq
where appropriateEq- Enums for discrete modes/states;
for optional fieldsOption<T>
5. Cross-Platform GUI Development
When building GUI applications, apply these practices:
Before doing any visual changes, check the
ui-guidelines.md at the root of the repo for general guidelines and best
practices for UI/UX development.
Architecture:
- Separate core logic from UI: business logic in a library crate, UI in the binary crate
- Use a message/command pattern to communicate between UI and logic layers
- Keep platform-specific code isolated behind trait abstractions or
gates#[cfg(target_os)] - Design for the event loop: avoid blocking the main/UI thread
Framework guidance (choose based on project needs):
- iced — Elm-inspired, pure Rust, good for data-driven UIs. Strengths: type-safe message passing, no unsafe, cross-platform. Use
oriced::Application
traits.iced::Sandbox - egui / eframe — immediate-mode, excellent for tools, dashboards, debug UIs. Strengths: very fast iteration, minimal boilerplate, easy embedding. Use
trait.eframe::App - Tauri — web-tech frontend with Rust backend. Strengths: small binary size, leverage web ecosystem, strong IPC. Use for apps where web UI is preferred.
- Slint — declarative UI with
markup language. Strengths: designer-friendly, embedded-capable, good accessibility..slint - gtk4-rs / relm4 — GTK4 bindings. Strengths: mature widget set, strong Linux integration. Use
for Elm-style architecture on top of GTK4.relm4 - Dioxus — React-like with RSX syntax. Strengths: familiar to web devs, cross-platform (desktop, web, mobile).
Cross-platform considerations:
- Test on all target platforms early and regularly (Windows, macOS, Linux at minimum)
- Use
ordirs
crate for platform-appropriate config/data/cache pathsdirectories - Handle HiDPI/scaling — use logical pixels, not physical pixels
- Respect platform conventions for keyboard shortcuts (Cmd vs Ctrl), file paths, and native look-and-feel
- Use
sparingly and only when truly needed; prefer cross-platform abstractionscfg(target_os) - For file dialogs, system notifications, and other OS integration, use
,rfd
, or similar cross-platform cratesnotify-rust
State management:
- Treat application state as a single source of truth; UI renders from state
- Use message/event enums to describe state transitions
- Keep state serializable where practical (enables save/restore, undo/redo)
- For complex state, consider a reducer pattern or
for thread-safe sharingArc<Mutex<State>>
Async and threading in GUI apps:
- Never block the UI thread — offload heavy work to background threads or async tasks
- Use channels (
,std::sync::mpsc
,crossbeam-channel
) to send results back to the UItokio::sync::mpsc - For async runtimes alongside GUI event loops, use the framework's built-in async support or run
on a separate threadtokio - Debounce expensive operations triggered by rapid UI events (typing, resizing)
6. Code Style
- Use the repo's
andrustfmt
configuration; never change them; fix all warningsclippy
for functions/variables/modules/files;snake_case
for types;PascalCase
for constantsUPPER_SNAKE_CASE- Group imports:
, external crates,crate::
; no glob imports in production codestd:: - Doc comments (
) on all public items with///
/# Errors
sections where applicable# Panics - Comments explain "why", not "what"; no commented-out code
- Functions ~50 lines max; extract helpers when they grow
overmatch
chains for multiple variants; guard clauses for early returnsif let
7. Dependencies
- Check the existing
before adding new dependenciesCargo.toml - Prefer well-maintained, widely used crates (check download counts, recent activity,
usage)unsafe - Pin major versions; use
for patch updatescargo update - Feature-gate optional functionality to keep compile times and binary size down
- For cross-platform apps, verify that dependencies support all target platforms
- Dependencies should be always kept up-to-date with the latest stable versions
Commonly useful crates:
- CLI:
(derive),clap
(progress bars)indicatif - Serialization:
+serde
/serde_json
/tomlron - Async:
(only when genuinely needed)tokio - Logging:
ortracing
+logenv_logger - File I/O:
(tests),tempfile
(traversal)walkdir - Cross-platform paths:
,dirsdirectories
8. Performance
- Use
/BufReader
for file I/OBufWriter - Pre-allocate
capacity when size is known; useVec
to avoid unnecessary allocationsCow<'_, str> - Use
(orstd::sync::LazyLock
) for expensive one-time inits like compiled regexesonce_cell::sync::Lazy - Profile before optimizing — use
,cargo flamegraph
for benchmarkscriterion - For GUI: keep frame budgets in mind (~16ms for 60fps); avoid allocations in hot render paths
9. Testing
- Unit tests:
at the bottom of each file;#[cfg(test)] mod testsuse super::* - File-based tests:
for temporary directoriestempfile::tempdir() - Follow Arrange-Act-Assert; use helper functions to build test fixtures
- Use
for enum variant checksassert!(matches!(...)) - Test happy paths, error conditions, and meaningful boundary values
- Add tests where it makes sense; don't add them purely for coverage numbers
- For GUI: test logic and state management independently from rendering; use snapshot/golden tests for UI if the framework supports it
10. Forbidden
code unless explicitly approved by the userunsafe
/unwrap()
in non-test codeexpect()- Error libraries other than
(noanyhow
,thiserror
, etc.) unless explicitly approvedeyre - Changing
orrustfmt
settings without explicit approvalclippy - Blocking the UI/main thread in GUI applications
11. Quality Validation
Run before completion (adjust package name to match the project):
cargo build -p <package-name> cargo clippy -p <package-name> -- -D warnings cargo test -p <package-name> cargo fmt -p <package-name> -- --check
For workspace-wide checks:
cargo build --workspace cargo clippy --workspace -- -D warnings cargo test --workspace cargo fmt --all -- --check
Never run git commit. Summarize changes to the user alongside any problems and caveats.
When to Use This Skill
- Writing new Rust applications, libraries, or tools
- Building cross-platform GUI applications in Rust
- Adding functionality to existing crates
- Refactoring, debugging, or reviewing Rust code
- Any Rust task where production-quality, idiomatic code is expected