Want true pub-sub semantics in Rust?
The Bus crate gives you SPโMC broadcast semantics.
Crossbeamโs MPSC supports multiple consumers, but it round-robins messages, not exactly what you want for fan-out.
https://t.co/RdrhaL31li
๐ฆ #Rust Tip #119:
Some folks suggest using std::panic::catch_unwind as a solution to the recent unwrap() panic that stopped the internet.
In my opinion this is an anti-pattern, some thoughts:
- bypasses memory safety constraints (e.g., panic in unsafe block)
@_Felipe Great idea if you want to jump straight into undefined behavior. One of the tenets in Rust is to prevent undefined behavior. In the case of unhandled errors (unrwap()) the sound option is to stop execution. There is unwrap_or_default() though...
#119 (contd.)
- imposes runtime cost by stack walking
- encourages using panic for control flow
- many APIs are not unwind-safe
- cannot catch "fatal" errors such as out-of-memory
@deviant_studio@grok They were basically calling a function that either returns a successful result or an error. Production code would normally handle the error case. Calling unwrap() will panic and halt execution if there was an error.
Cloudflare generated many millions of HTTP 5XX responses today. They were triggered because code in a core proxy called .unwrap() on a Result for an operation that was expected to never fail.
๐ฆ #Rust Tip #118:
Result::and_then lets us chain operations that return Result, bypassing nested pattern matching. Although the ? operator often accomplishes the same, and_then allows us to remain in a more functional "combinator style".
This is gold if you're using async Rust ๐ฏ
๐ channels-console โ A TUI dashboard for inspecting std/tokio/futures/crossbeam channels.
๐ Watch messages, queue depth, throughput & memory usage live.
๐ฆ Written in Rust & built with @ratatui_rs
โญ GitHub: https://t.co/DgetvpBJGI
#rustlang #ratatui #tui #async #concurrency #tokio #debugging
@barettorein @axiosopher Not sure I follow 100%, if statements don't need round parens, for example.
Also, try a C++ closure
auto add = [&sum](int v){ sum += v; };
ampersand and all types of possible parens
Rust:
let mut add = |v| { total += v; };