rust-system-event-driven
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 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 |
More from pproenca/dot-skills
zod
Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).
2.0Kclean-architecture
Clean Architecture principles and best practices from Robert C. Martin's book. This skill should be used when designing software systems, reviewing code structure, or refactoring applications to achieve better separation of concerns. Triggers on tasks involving layers, boundaries, dependency direction, entities, use cases, or system architecture.
1.4Kemilkowal-animations
Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.
918vitest
Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.
907typescript
This skill should be used when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
821nuqs
nuqs (type-safe URL query state) best practices for Next.js applications. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, or Next.js routing with state.
735