Daily Rust

458 posts

Daily Rust banner
Daily Rust

Daily Rust

@rustoftheday

Daily tips & tricks for Rust 🦀 programming. Following back all accounts with 🦀 or 🐪 in their profile.

شامل ہوئے Kasım 2023
780 فالونگ3.3K فالوورز
NeoSmart Technologies
NeoSmart Technologies@NeoSmart·
@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
1
0
0
9
Daily Rust
Daily Rust@rustoftheday·
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
1
2
42
3K
Daily Rust
Daily Rust@rustoftheday·
@nother_pleb Agree to using it as a safety net, but not as a primary way of handling errors.
English
0
0
0
43
tcerqueira
tcerqueira@nother_pleb·
@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
1
1
4
252
Daily Rust
Daily Rust@rustoftheday·
🦀 #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)
English
9
0
48
4.1K
Daily Rust
Daily Rust@rustoftheday·
@_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
1
0
3
259
Felipe O. Carvalho
Felipe O. Carvalho@_Felipe·
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.
Felipe O. Carvalho tweet media
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
39
3
79
113.9K
Daily Rust
Daily Rust@rustoftheday·
#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
0
0
9
686
Daily Rust
Daily Rust@rustoftheday·
@LundukeJournal We should note it wasn't a memory issue but unsound handling of an error state.
English
0
0
3
77
Daily Rust
Daily Rust@rustoftheday·
@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
0
0
0
20
deviant
deviant@deviant_studio·
@rustoftheday @grok can you explain? what is unwrap(). what the hell happened with cloudflare?
English
2
0
0
258
Dmitrii Kovanikov
Dmitrii Kovanikov@ChShersh·
@jino_rohit Brother, I see C, not C++ Throw some templates, lambdas and smart pointers there.
English
6
1
128
7.5K
Jino Rohit
Jino Rohit@jino_rohit·
Learning C++ is super rewarding and humbling. Today I'm working through the Byte Pair tokenizer from karpathys code and port to C++. I'm taking it as slow as I can to test, write and re-write everything.
Jino Rohit tweet media
English
37
31
915
39.9K
Daily Rust
Daily Rust@rustoftheday·
🦀 #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".
Daily Rust tweet media
English
12
13
172
11.5K
Daily Rust
Daily Rust@rustoftheday·
@yotstack There is a .then() method for async futures in Rust as well, but mostly .await is sufficient.
English
0
0
1
161
Ayotunde Ajayi
Ayotunde Ajayi@yotstack·
@rustoftheday I wondered why Rust would not have something similar to Promise.then as in Javascript
English
1
0
1
231
Dmitrii Kovanikov
Dmitrii Kovanikov@ChShersh·
Spent more than 15 minutes writing a simple Stack Machine evaluator in C++ using std::visit and std::variant. Unacceptable. Time to end this day.
English
8
1
72
6.4K
Daily Rust
Daily Rust@rustoftheday·
@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
1
0
0
14
Sofia
Sofia@barettorein·
@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
1
0
0
29