Imagine this fairly basic situation: you have a button object. When clicked, it triggers a closure (callback). And that closure needs to change the button's text to e.g. "Clicked!".
To do this in Rust, the closure needs a mutable reference to the button. However, the GUI event loop also needs a reference to the button to draw it on the screen. In Rust, you can have many immutable references, __or__ exactly one mutable reference, but never both at the same time. Since the GUI framework holds the button, it won't let your closure mutably borrow it at the same time.
Why would they need them at the same time? The overall state will contain the button.
Many interactive programs can be GetInput(); ChangeState(); DrawState();
Why wouldn't their lifetimes be isolated?
Also the drawing doesn't need a mutable reference.
Do you find anything "bad" about this code solving the problem?
Prints: