Details

Language / Topic
rustRust
Category
Libraries
Source
tokio-rs

Rules

balanced
- Use `#[tokio::main]` on `async fn main()` and `#[tokio::test]` on async test functions — Tokio's runtime handles the async executor.
- Use `tokio::spawn()` for concurrent tasks and `tokio::select!` for racing multiple futures — both are zero-cost abstractions over the runtime.
- Use `tokio::sync::Mutex` (not `std::sync::Mutex`) for shared state in async code — std Mutex blocks the thread, Tokio Mutex yields to the runtime.
- Use `tokio::sync::Mutex` (not `std::sync::Mutex`) for async-safe locking.
- Use `tokio::sync::mpsc` for multi-producer channels, `oneshot` for single-response patterns.
- Use `tokio::time::timeout()` to bound async operations. Never let operations hang indefinitely.
- Use `tokio::fs` for async file operations instead of blocking `std::fs` on the async runtime.