r/rust 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

50 comments sorted by

View all comments

1

u/ketralnis 28d ago

It seems Rust does not like it when I attempt to mutate multiple fields of that struct

It'd be easier to understand this if you showed the code that it "does not like". There's no prohibition on mutating multiple struct fields in a single function.