> rust-system-event-driven
Rust event-driven system programming best practices for async runtimes, channels, sockets, terminals, and concurrency. This skill should be used when writing, reviewing, or refactoring Rust applications with async I/O, multi-threading, terminal interfaces, or network communication. Triggers on tasks involving tokio, async/await, channels, sockets, TTY handling, signals, and streaming I/O.
curl "https://skillshub.wtf/pproenca/dot-skills/rust-system-event-driven?format=md"Rust System Event-Driven Best Practices
Comprehensive best practices guide for event-driven system programming in Rust. Contains 42 rules across 8 categories, prioritized by impact to guide async runtime usage, channel communication, threading, networking, and terminal handling.
When to Apply
Reference these guidelines when:
- Building async applications with Tokio or async-std
- Implementing network servers or clients
- Writing terminal user interfaces (TUIs)
- Managing concurrent tasks and shared state
- Handling Unix signals and graceful shutdown
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Async Runtime Patterns | CRITICAL | async- |
| 2 | Channel Communication | CRITICAL | chan- |
| 3 | Threading & Synchronization | HIGH | sync- |
| 4 | Socket & Network I/O | HIGH | net- |
| 5 | Terminal & TTY Handling | MEDIUM-HIGH | term- |
| 6 | Signal & Process Control | MEDIUM | sig- |
| 7 | File I/O Streaming | MEDIUM | io- |
| 8 | Event Loop Architecture | LOW-MEDIUM | loop- |
Quick Reference
1. Async Runtime Patterns (CRITICAL)
async-spawn-blocking- Use spawn_blocking for CPU-bound workasync-select-biased- Use biased select for priority handlingasync-no-std-block- Avoid std blocking calls in async contextasync-cancellation-safe- Design cancellation-safe async operationsasync-task-local- Use task-local storage for request contextasync-structured-concurrency- Use JoinSet for structured concurrency
2. Channel Communication (CRITICAL)
chan-bounded-backpressure- Use bounded channels for backpressurechan-oneshot-response- Use oneshot channels for request-responsechan-broadcast-fanout- Use broadcast channels for fan-outchan-watch-state- Use watch channels for shared statechan-graceful-shutdown- Use channel closure for graceful shutdown
3. Threading & Synchronization (HIGH)
sync-arc-mutex-shared- Use Arc<Mutex> for shared mutable statesync-rwlock-read-heavy- Use RwLock for read-heavy workloadssync-atomic-counters- Use atomics for simple counters and flagssync-avoid-lock-await- Avoid holding std Mutex across awaitsync-semaphore-limit- Use Semaphore to limit concurrencysync-parking-lot- Use parking_lot for high-contention locks
4. Socket & Network I/O (HIGH)
net-split-reader-writer- Split sockets into reader and writer halvesnet-framing-codec- Use framing for message-based protocolsnet-connection-pool- Use connection pools for repeated connectionsnet-timeout-all-io- Add timeouts to all network operationsnet-tcp-nodelay- Set TCP_NODELAY for low-latency protocolsnet-graceful-disconnect- Implement graceful connection shutdown
5. Terminal & TTY Handling (MEDIUM-HIGH)
term-raw-mode-restore- Always restore terminal state on exitterm-alternate-screen- Use alternate screen for full-screen appsterm-async-event-stream- Use async event stream for terminal inputterm-buffered-output- Buffer terminal output for performanceterm-handle-resize- Handle terminal resize events
6. Signal & Process Control (MEDIUM)
sig-ctrl-c-graceful- Handle Ctrl-C for graceful shutdownsig-unix-signals- Handle Unix signals asynchronouslysig-child-reap- Reap child processes to avoid zombiessig-timeout-shutdown- Set shutdown timeout to force exit
7. File I/O Streaming (MEDIUM)
io-async-file-ops- Use async file operations in async contextio-stream-large-files- Stream large files instead of loading entirelyio-copy-bidirectional- Use copy_bidirectional for proxyingio-pipe-communication- Use pipes for process communicationio-flush-before-read- Flush writes before expecting responses
8. Event Loop Architecture (LOW-MEDIUM)
loop-actor-model- Use actor pattern for stateful componentsloop-event-types- Use typed events over dynamic dispatchloop-state-machine- Model protocol state as type-safe state machineloop-layered-architecture- Separate I/O from business logicloop-cancellation-token- Use CancellationToken for coordinated shutdown
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
> related_skills --same-repo
> rust-write-tests
Skill for writing expert-level Rust tests. Teaches the "What Could Break?" framework, five transformations from superficial to expert tests, flake hunting protocol, intent-based assertions, naming conventions, and a mandatory self-review checklist. Triggers on writing Rust tests, designing test cases, improving test quality, or reviewing test coverage.
> rust-implement
Write production-grade Rust code using a multi-pass approach. Design types first, then implement, then simplify, then verify with automated lint. Use this skill whenever writing new Rust functions, structs, modules, or features. Triggers on Rust implementation, new Rust code, Rust functions, Rust modules, error handling in Rust, async Rust, or type design in Rust.
> valid-skill
A valid test skill with proper formatting. This skill should pass all validations and serves as a reference for the expected format.
> too-long-skill
This skill has more than 500 lines which should fail validation.