In related threads 1 and 2 we had discussed what exactly we're paying the runtime cost of a Rc<RefCell<T>>
interior mutability pattern for. (Specifically, why we're paying for dynamic tracking of the RefCell in the presence of Rc.) It was suggested that it is best to avoid the interior mutability pattern as this often leads to code patterns that are basically a 1:1 translation of the patterns used in other procedural or object-based languages. I'm all for that, but would like to understand how to do it.
I've put my application in a playground as a small example. Following the example given by @Hyeonu I used Person
as my example. Persons are stored in 2 tables using 2 indices. Sometimes, depending on the user input, the program must maintain a "current person" while simultaneously be able to react to events that could concern the current person or other persons. Events change a person's state, which I simulated using a "mood" field.
This playground shows the program. I have used a random number generator whenever my program must react to external events. In the code, I'm using the Rc<RefCell<T>>
interior mutability pattern throughout - what I'm looking for advice on is how to avoid it so that I can directly benefit from Rust's guarantees.