🦀 #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 #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 #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.
🦀 #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 #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 #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#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 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)]
🦀 #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 #103:
Want to spawn threads without managing handles?
std::thread::scope blocks until all threads terminate within the defined closure.
Example:
280 Followers 2K Following🚀 Golang Backend Engineer | Building in public
🤖 Exploring AI & RAG systems
🔨 Crafting tools that matter
🎯 On a journey to indie hacking
💡 Sharing backend
16K Followers 3K FollowingScientist at IDM. ♥s epidemiology, running, probability+statistics, 🦀, fly fishing, backpacking. Author of book Bioinformatics Data Skills. All views my own.
15 Followers 220 FollowingFormer(C++)(Java)(.NET)(Python)=Current(Rust ),Philosopher (Socrates) , Movie(Inception) . Literature (1984 or Crime and Punishment)
16K Followers 3K FollowingScientist at IDM. ♥s epidemiology, running, probability+statistics, 🦀, fly fishing, backpacking. Author of book Bioinformatics Data Skills. All views my own.
790 Followers 4K FollowingFounder @blok_cap protocol DAO, decentralizing Wealth Management. Everyone deserves a Garden 🌱 🌿 🌳 and the help of a professional Gardener 👨🌾
1K Followers 245 FollowingRewriting prod app from TS to Rust by day, dreaming of Camls by night.
I might stream tomorrow or never.
I don't agree with any of your opinions.
🏳️🌈
730 Followers 732 FollowingI’m a software developer, co-founder and tech lead of Gistia. I am a tech enthusiast that parachuted into the healthcare industry.
I am a walking metamorphosis
2K Followers 305 FollowingOne of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die.
8K Followers 2K FollowingCatholic ✝️ • Rust Dev & Content Creator 🦀 Learning & Building embedded systems with Rust • Biochemist • Fullstack JS Dev • chill guy