Daily Rust (@rustoftheday) 's Twitter Profile
Daily Rust

@rustoftheday

Daily tips & tricks for Rust 🦀 programming.

Following back all accounts with 🦀 or 🐪 in their profile.

ID: 1721578494524792832

calendar_today06-11-2023 17:21:36

396 Tweet

2,2K Takipçi

747 Takip Edilen

Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #103: Want to spawn threads without managing handles? std::thread::scope blocks until all threads terminate within the defined closure. Example:

🦀 #Rust Tip #103: 

Want to spawn threads without managing handles?

std::thread::scope blocks until all threads terminate within the defined closure.

Example:
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #104: This is a nice one: Have you ever tried to compare the variant of two enums? Usually this requires a cascade of match statements. However, mem::discriminant can be used in this situation. This works specifically in cases where the enum doesn't derive Eq.

🦀 #Rust Tip #104:  
This is a nice one: Have you ever tried to compare the variant of two enums? Usually this requires a cascade of match statements.   
However, mem::discriminant can be used in this situation. This works specifically in cases where the enum doesn't derive Eq.
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #105: Searching for ways to allow a warning I learned that there are "inner" and "outer" attributes. - Inner #![...] applies broadly to the whole module or crate: #![allow(dead_code)] - Outer #[...] applies to the following item: #[derive(Debug)]

Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust #Crate 22: Are you dissatisfied with the performance hit of your println! debugging output? Do you think env_logger is boring? Turbocharge your log outputs with high performance and fine-grained structured control using the tracing crate: crates.io/crates/tracing

🦀 #Rust #Crate 22: Are you dissatisfied with the performance hit of your println! debugging output? Do you think env_logger is boring?   

Turbocharge your log outputs with high performance and fine-grained structured control using the tracing crate: crates.io/crates/tracing
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #105: Want to make sure your loop breaks out to a specific level? Rust allows using labels to finetune the exit point:

🦀 #Rust Tip #105:

Want to make sure your loop  breaks out to a specific level? Rust allows using labels to finetune the exit point:
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #106: Boxing large enum values can be beneficial to save stack space and to prevent recursion-bombs 💣, by moving these payloads to the heap.

🦀 #Rust Tip #106:

Boxing large enum values can be beneficial to save stack space and to prevent recursion-bombs 💣, by moving these payloads to the heap.
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #107: TIL about the #[cold] attribute for functions that don't get called very often. This helps the compiler prioritize hot path functions for better instruction cache performance. #[cold] can also be used to tag enum variants to optimize memory layout.

🦀 #Rust Tip #107:

TIL about the #[cold] attribute for functions that don't get called very often. This helps the compiler prioritize hot path functions for better instruction cache performance. #[cold] can also be used to tag enum variants to optimize memory layout.
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #108: I always enjoy the power of Rust #iterators. Here are two utility functions that you might not know about: .peekable() : Allow peeking at next element without consuming it .partition(cond_fn): Partition an iterator into separate collections with a condition

🦀 #Rust Tip #108:

I always enjoy the power of Rust #iterators. Here are two utility functions that you might not know about:

.peekable() : Allow peeking at next element without consuming it

.partition(cond_fn): Partition an iterator into separate collections with a condition
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #111: You can use the examples/ directory in your crate and cargo run --example <name> to run quick experimentations, demos or tests without affecting your main.rs file.

Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #112: Rust will happily compile and call C functions in unsafe mode. Just declare them in an extern "C" block. Great for interop with legacy code or standard library C functions.

🦀 #Rust Tip #112:

Rust will happily compile and call C functions in unsafe mode. Just declare them in an  extern "C" block. Great for interop with legacy code or standard library C functions.
Daily Rust (@rustoftheday) 's Twitter Profile Photo

🦀 #Rust Tip #113: build.rs is secretly a decent C build system. You can compile wrappers + link C SDKs for Rust wrappers and calling into C code. BTW those println!s are "hidden" build instructions to Cargo. Who needs Makefiles? 🦀

🦀 #Rust Tip #113:
build.rs is secretly a decent C build system.
You can compile wrappers + link C SDKs for Rust wrappers and calling into C code. BTW those println!s are "hidden" build instructions to Cargo.
Who needs Makefiles? 🦀