Did you know that in Rust, 'let _ = ...' and 'let _unused = ...' are NOT the same thing?
I didn't until today!
Did you know that in Rust, 'let _ = ...' and 'let _unused = ...' are NOT the same thing?
I didn't until today!
@pg Funnily, I kind of knew this before reading this 🤔
Maybe the "ignore" notation of just underscore is described somewhere in the teaching materials.
@pg I wrote an article a few years ago with some expanded history and explanation:
https://codeandbitters.com/drop-or-not/
Fun to read the 2013 discussion where Nico first argued it’s wrong, then changed his mind.
@pg Interesting! This lead me into a short rabbithole. This is what I found:
- let _ = ... is pattern matching (https://doc.rust-lang.org/stable/reference/patterns.html#grammar-WildcardPattern states: "Unlike identifier patterns, it does not copy, move or borrow the value it matches")
- let _unused = ... assignes a variable (which is only unused by convention)
If you follow the reference carefully, it turns out that _ is not a valid identifier! It is actually a keyword (https://doc.rust-lang.org/stable/reference/keywords.html#r-lex.keywords.strict)
TIL