10 points

Whenever I need a struct, I flip a coin to decide if it should be above or below the one I’m currently writing.

permalink
report
reply
6 points

Order? I write them as I need them… is my code chaos, yes!

permalink
report
reply
5 points

Enums/Structs first, but those 2 are mixed, and any impl for them will be directly after the definition of the type itsef. Free functions last.

permalink
report
reply
4 points
*

I like to write them in blocks of concerns: ie there should be the minimum amount of jumping around the file when reading them. If there are a lot of these separate blocks in a single file, that is a good indication that it has grown enough and it is time to separate them into different files. But inside the blocks it would be usually struct/enums (no implicit order since they are just sum/product types), impl blocks, free functions (that are usually common functionality between the impl blocks).

permalink
report
reply
3 points

I place them in that order, enums, structs, functions.

permalink
report
reply

Rust

!rust@programming.dev

Create post

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits
  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

Community stats

  • 420

    Monthly active users

  • 839

    Posts

  • 3.8K

    Comments