|
|
Subscribe / Log in / New account

Underscores in Rust

Underscores in Rust

Posted Feb 12, 2025 8:31 UTC (Wed) by ralfj (subscriber, #172874)
In reply to: Underscores in Rust by adobriyan
Parent article: Maintainer opinions on Rust-for-Linux

The thing is, it's not just renaming a variable. '_' is not a variable name, it is an entirely different syntactic entity: it is a *pattern*. Other examples of patterns are 'Some(x)' and '(a, b, c)'. The meaning of the '_' pattern is "discard the value matched against this pattern as soon as possible".

That said, I agree this is quite surprising, and I've been bitten by this myself in the past.


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds