Modelling data structures and the constant need to rewrite them
⚓ Rust 📅 2025-09-28 👤 surdeus 👁️ 6Hi!
I am new to rust and I find myself quite often in the following situation, raising the same question again and again:
The question has two parts, but they are closely related, therefore, I bundle them into one post.
Part #1 (practical problem)
Often, my data modelling ends up with nested structs that make logically sense (to me). Maybe because I am still mentally bound to the OO world.
The root cause of the following problem is the fact that child methods need to call parent methods (sometimes mutable and sometimes immutable), but Rust does not like this approach (borrow checker issues). Here is an example to illustrate my problem:
What is the best way to solve this issue, how should data be structured to prevent borrow checker issues?
I did a lot of research and all I could find boils down to one of the following approaches:
- Use interior mutability in some way (I would like to not do this, because I would like to learn how to do it properly and I am lacking experience to fully understand the possible pitfalls)
- Structure the data like an ECS. This seems like an overkill for my small cli tools.
Bonus question: Is there a clean way to make my snippet work?
Part #2 (architectural problem)
I have made the observation that the following scenario happens quite often in Rust (more than in other languages):
One takes a lot of care to design the model of an application and everything works after the initial implementation. But then requirements change and new features shall be added. The data model fits less and less and new borrow checking issues arise, requiring the rewrite of a lot of code to adapt to an updated data model. How to prevent this, is it even possible?
I am aware that such adaptations are normal and required in other languages, too. But my impression is that Rust especially, requires more reimplementation than others.
Don't get me wrong, I do not blame Rust. I am fully aware of the fact that all problems might be/are related to my lack of experience  .
 .
Are there general design concepts for Rust to reduce the amount of refactoring? All I could find tackles only the most basic scenarios...
Thank you all!
BR,
thedude
1 post - 1 participant
🏷️ Rust_feed