Daily Rust
458 posts

Daily Rust
@rustoftheday
Daily tips & tricks for Rust 🦀 programming. Following back all accounts with 🦀 or 🐪 in their profile.
शामिल हुए Kasım 2023
780 फ़ॉलोइंग3.3K फ़ॉलोवर्स

@rustoftheday This is a terrible crate that should not be used outside of extremely, *extremely* niche situations. It bust waits and each consumer will take 100% of a core waiting for messages. DO NOT USE.
English

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.
crates.io/crates/bus
English

@nother_pleb Agree to using it as a safety net, but not as a primary way of handling errors.
English

@rustoftheday Not really, catch_unwind is a great solution for network services, you put on the top level to catch and report a server error so it doesn't take your whole instance down. It's a safety net, not error handling per se. Also, panics must be safe, unsafe code must be ready to handle
English

@_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...
English

We need an .unwrap_in_debug_builds_but_just_carry_on_in_release_builds() function in Rust to stop these incidents.
I have recently caused problems with a panic that would be informative in debug builds during testing but didn’t really have to fire in production.

Matthew Prince 🌥@eastdakota
We let the Internet down today. Here’s our technical post mortem on what happened. On behalf of the entire @Cloudflare team, I’m sorry. blog.cloudflare.com/18-november-20…
English

#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
English
Daily Rust रीट्वीट किया

You generally want a Clippy linter like this one in your Rust production code

AstraKernel 💫@AstraKernel
🦀 Bad news everyone - unwrap() is the reason behind cloudflare outage >The FL2 Rust code that makes the check and was the source of the unhandled error is shown below blog.cloudflare.com/18-november-20…
English

@LundukeJournal We should note it wasn't a memory issue but unsound handling of an error state.
English

September, 26: Cloudflare rewritten in “memory safe” Rust.
The change is touted as “faster and more secure” because of Rust.
blog.cloudflare.com/20-percent-int…
November, 18 (53 days later): Cloudflare has a massive outage, which took down large portions of the Internet, because of a memory error… in that Rust code.
blog.cloudflare.com/18-november-20…


English

@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.
English
@rustoftheday @grok can you explain? what is unwrap(). what the hell happened with cloudflare?
English

Don't use unwrap() in your production code, boys and girls! 😃
Tim McNamara@timClicks
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.
English

@jino_rohit Brother, I see C, not C++
Throw some templates, lambdas and smart pointers there.
English
Daily Rust रीट्वीट किया

Animate anything with Rust 🦀
🌀 KramaFrame — A simple, generic, and flexible keyframe animation library.
⚡ Manage multiple animations, apply easing functions, and map progress to any range.
🐁 Includes a terminal demo w/ @ratatui_rs
⭐ GitHub: github.com/CosmoBunny/kra…
#rustlang #animation #library #programming #terminal #ratatui #tui
English

@yotstack There is a .then() method for async futures in Rust as well, but mostly .await is sufficient.
English

@rustoftheday I wondered why Rust would not have something similar to Promise.then as in Javascript
English
Daily Rust रीट्वीट किया

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: github.com/pawurb/channel…
#rustlang #ratatui #tui #async #concurrency #tokio #debugging
English

@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; };
English

@rustoftheday @axiosopher Rust is much messier than C++ syntax wise, far more ampersands than i'd like and it feels like it needs a metric fuckton of round parens even if sometimes you can avoid them maybe
English
Daily Rust रीट्वीट किया




