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?

  • nerdbloodOP
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    Also, move out special types to types.rs, error types to errors.rs to keep the area with the actual algorithms more clear.

    Ok this is totally something my code base needs. Very actionable feedback.

    And yeah that’s one of the things I love about rust; it will tell me everywhere things are out of wack. It’s such a different experience from back when I had large JavaScript code bases. Make changes and pray lol.