this post was submitted on 18 Aug 2023
26 points (93.3% liked)

Rust

5953 readers
6 users here now

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)

founded 1 year ago
MODERATORS
 

I've mostly been putting functions, structs enums and tests in the same file and it's starting to feel like a mess... I am constantly losing track of which function is where and I'm never quite sure if I have code in the right place. I know this is kind of vague, but that's been my general feeling while working in my largest personal project so far. It's essentially a large Algorithm that has many smaller steps that needs to run in a sequence.

I think I might just have too many loose functions and maybe I should use more impl methods and traits? I'm also thinking I should try the builder pattern in a few spots.

Anyone have any guidance on code organization in rust?

you are viewing a single comment's thread
view the rest of the comments
[–] lysdexic@programming.dev 3 points 1 year ago* (last edited 1 year ago)

I am constantly losing track of which function is where and I’m never quite sure if I have code in the right place.

That's not a Rust concern but a software architecture concern. The software architecture pattern you follow determines how the project is structured taking into account what requirements it needs to comply to address common requirements, such as ensuring that things that change a lot will be easier to change and things that don't change won't get in the way.

I recommend you read up on topics such as layered architecture, hexagonal architecture/ports and adapters, clean architecture, etc.