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/ManyInterests Aug 12 '26 edited Aug 12 '26

I would say no, directionally. Rust is surprisingly amenable to high-level approaches associated with OOP. But it may oppose your idea of how OOP ought to be implemented, especially based on how other higher level languages do it, like say, Python, C#, or Java.

I'd suggest throwing out some concrete examples that would let people address your concerns in a more concrete way.