Dev Tools · 1h ago
Rust Gotcha: Assignment Returns Unit Type, Not Value
A Rust developer discovered that assignment expressions evaluate to the unit type `()`, not the assigned value. Using `and_then` with an assignment in `Some()` produced `Option<()>` instead of `Option<&mut String>`. This behavior stems from Rust's design where assignment is an expression returning `()`.
Meridian48 take
This is a fundamental Rust gotcha that trips up newcomers, but it's a well-documented language design choice, not a bug.
rustprogramming-gotchas