TIL that Rust supports inline struct definitions! https://github.com/rust-lang/rust/commit/6d43225bfb08ec91f7476b76c7fec632c4a096ef#diff-1dfa77331261e81c069657949febee032512a702bfe5865d7993cfc9f577f2f3
They still need names, but it allows you to define structs only used in a single function.
miniblog.
Related Posts
Structs are great in Rust, but sometimes I find them a bit heavyweight. There's a little more syntax than e.g. OCaml, for type definitions and usages.
I end up using more structs (records) in OCaml as a result.
rust-analyzer has "convert tuple to named struct", which helps.
Linux historically used magic numbers to recognise structs being used incorrectly with void pointers. These have been increasingly replaced with type-safe macros: https://lwn.net/SubscriberLink/915163/ba83480903b82cb8/
Some of the original files were unchanged from the 90s!
Rust 1.40 adds a feature that stops consumers matching on structs or enums exhaustively, so extending them is not a breaking change!
There's a cute todo!() macro too.