3 ms·
> Every struct (or at least every useful struct!) refers to data Not true, zero-sized structs are quite useful too. They can be used to fulfill traits, indicat
by TheDong 9y ago
> Every struct (or at least every useful struct!) refers to data
Not true, zero-sized structs are quite useful too. They can be used to fulfill traits, indicate certain errors (often in enums), etc.
A couple quick examples from the stdlib:
https://github.com/rust-lang/rust/blob/1.22.1/src/libstd/sync/mpsc/mod.rs#L579-L581 https://github.com/rust-lang/rust/blob/1.22.1/src/libstd/syn...
https://github.com/rust-lang/rust/blob/1.22.1/src/libstd/collections/hash/map.rs#L31-L33 https://github.com/rust-lang/rust/blob/1.22.1/src/libstd/col...
I recommend watching this excellent rustconf 2017 talk for more information; it heavily features information on how zero-sized types can be used: https://www.youtube.com/watch?v=wxPehGkoNOw https://www.youtube.com/watch?v=wxPehGkoNOw
- deleted 9y ago[deleted]
- sagichmal 9y agoBy opening with "Not true" you're establishing a contrarian position, which puts people -- likely the author, potentially even the reader -- on the defensive, emotionally. It's sufficient and actually a lot nicer to simply state your point: e.g. "Zero-sized structs are quite useful too."
- littlestymaar 9y agoI agree for the author's point of view, but as a reader I enjoy contradiction and argumentation because that's where I learn most. Then when I see someone starting with `not true` or `I disagree`, I immediately interested in reading more. YMMV though.