
Message Passing in Rust With std mpsc Channels Step by Step
std::sync::mpsc moves values between threads through a channel. Learn send, recv, iterating, multiple producers and what a closed channel means.
Everything you need to level up your coding skills.

std::sync::mpsc moves values between threads through a channel. Learn send, recv, iterating, multiple producers and what a closed channel means.

Implement From and you get Into for free. Learn the conventions, how the question mark uses From, and when TryFrom is the right trait.

Use thiserror when callers need to match on what went wrong and anyhow when they only need to read it. Here is the rule, the code for each, and how to mix them.

A Rust program that hangs is often a deadlock. Capture every thread's stack with gdb, parking_lot deadlock detection or tokio-console, and read who waits for what.

Declare the oldest Rust your crate supports with rust-version, test it in CI, and understand how Cargo resolves dependencies against it. Also, a policy for when to raise it.

A parser that accepts any input can be made to use unbounded memory, time or stack. Set limits on size, depth and time, and know which crates already have them.

Assert that code panics with should_panic and a message, or with catch_unwind for finer control. Know the traps: unrelated panics passing, Result tests and panic=abort.

Find memory errors in unsafe Rust with AddressSanitizer, ThreadSanitizer and MemorySanitizer on nightly, and Miri for interpretation. Flags, build-std, output and limits.

Build a fully static Rust binary for the musl target and run it from a scratch image. Covers the target, linker, OpenSSL and DNS caveats, the allocator and how to verify.

Choose log levels by who reads them and when: what belongs at error, warn, info, debug and trace in a Rust service, what never to log, and how much is too much.

sort is stable and allocates, sort_unstable does not and is usually faster. Learn when stability matters, sort_by_key pitfalls and the cached-key variant for expensive keys.

Tracing replaces log lines with spans and events: a span is a period of work, an event is a moment. Learn the macros, fields, instrument, subscribers and filters.
We send one email when a new post is published. No spam.