Press enter or click to view image in full size
I love Rust. It’s safe. It’s fast. It’s powerful. But after 1 year of writing it professionally, I have to admit: Rust can be completely unreadable.
For a language that prides itself on memory safety and fearless concurrency, it sure does induce fear when I revisit my own code six months later. Last week, I stared at a wall of lifetimes, impl Traits, and cryptic macros for an hour before remembering what I was trying to accomplish. If you’ve been there too, you’re not alone. Let’s talk about some of Rust’s biggest readability offenders and how I’ve learned to fight back.
1. Lifetimes: The Hieroglyphics of Rust
Lifetimes are Rust’s way of ensuring memory safety, but they also have a special talent for making me question my career choices.
Exhibit A:
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() { x } else { y }
}The first time I saw this, I thought someone had accidentally leaned on their keyboard. 'a is a lifetime parameter, ensuring that x and y live long enough. But for simple cases like this, it's unnecessary mental overhead.
How I make it readable:
fn longest(x: &str, y: &str) -> &str {
if x.len() > y.len() { x } else { y…