idiomatic-rust-approaches
Core mental models
Thinking in Rust (not in Java/C++/Python)
When to use: Whenever you start a new Rust project or feel frustrated fighting the compiler.
The idea: Rust looks familiar (structs ≈ classes, traits ≈ interfaces) but is fundamentally different. The borrow checker, ownership model, and lack of inheritance mean traditional OO patterns lead to dead ends. Success requires unlearning habits from other languages and adopting Rust-native thinking.
How to apply: When the compiler rejects your design, step back and ask whether you're trying to express an OO pattern that doesn't fit. Redesign data flow so that ownership is clear and mutation is contained.
Pitfalls: Treating structs as classes and traits as interfaces leads to brittle code held together with clone() and Rc<RefCell>.
Ownership as a design philosophy
When to use: When architecting data structures, data flow, and module boundaries.
The idea: Ownership isn't just a compiler rule — it's a design tool. Data should have one clear owner at any time. Structure your system so that ownership flows naturally downward (from producers to brokers to consumers), and mutability stays at the edges, isolated from shared data paths.
How to apply: Design data flows downward. Producers send immutable data to brokers, brokers coordinate, consumers own and isolate state. Modules become interface boundaries.