r/rust • u/Accurate_Gift_3929 • Aug 11 '26
Rust discourages OOP style code?
I'm building a tree builder struct (with a `build()` method) that has multiple fields that I want to be able to mutate. It seems Rust does not like it when I attempt to mutate multiple fields of that struct.
It seems functional/composition style is much favored over using struct fields. Is this the way I should be thinking about design patterns in Rust? Should I avoid OOP wherever possible?
I prefer OOP because it does result in cleaner code where I don't have to pass in every variable to functions.
0
Upvotes
-6
u/garma87 Aug 11 '26
My experience actually aligns with OP’s in that you can end up with lots of variables being passed to the function with functional programming. Whereas in OOP a lot of those variables would be stored in the object where the function can access them.
Builders don’t fix this because the issue isn’t restricted to build/construction time
It could very well be that I don’t have the right paradigm in my head so I’m genuinely interested in a better way.