In a struct, you typically want only owned data types. If you’re passing something as a parameter to a function, you typically want only references.
In a sense, that pushes your program to be very tree-shaped. Your data is initialized and held at the root of the tree (or a sub-tree) and only temporarily passed down as a reference.
In my experience, following this rule gets you there for 80% of programs. Only really more complex programs or libraries may need to deal with lifetimes and the various cop-out mechanisms.
If you’re hurting your brain, that’s probably because you’re experienced in other languages and have design patterns in mind that don’t work with this model.
In a struct, you typically want only owned data types. If you’re passing something as a parameter to a function, you typically want only references.
In a sense, that pushes your program to be very tree-shaped. Your data is initialized and held at the root of the tree (or a sub-tree) and only temporarily passed down as a reference.
In my experience, following this rule gets you there for 80% of programs. Only really more complex programs or libraries may need to deal with lifetimes and the various cop-out mechanisms.
If you’re hurting your brain, that’s probably because you’re experienced in other languages and have design patterns in mind that don’t work with this model.