I'm working on a TUI using Cursive and I'm stuck using Arc's in combination with closures.
The minimal example I made is already quite large, so forgive me for linking to this github repo.
The Controller owns the UI thread, owns the receiving end of a channel and it owns application state; in my hobby project a lot more happens in these parts but I kept it simple for this example.
The problem I'm facing is that I need to know at all times what the current selected_chain is. The user is able to select a different chain throughout the application (using a menubar that ultimately sends a message to the Controller through a channel) and at some other parts in the application I need to know the current selected_chain. When I initiate the app, I wrap the chain in a RwLock (so that I can change the contents of Chain at some point) and then in an Arc, so that I can use it across threads. Then I clone this selected_chain and give it to both the UI and to the Controller itself, so that I can use it in the UI whenever I need it (Cursive uses closures to send updates to the UI), and so that I can update it in the Controller whenever a message arrives in the channel.
But whenever I change the selected_chain in the app, the selected_chain in the UI parts 'sticks' to the value it was initiated with. And I don't understand why this happens, as ultimately, I'm still referencing the same selected_chain in the controller using clones.
What am I missing?