Hello,
before aksing this I want to say that I know why this is not working. I would like to find a different way to do this or maybe a workaround.
I have a GUI struct with a vec of buttons. In the handle_input method I would like to iterate over all buttons and call the handle_click function which mutates the gui (basically self).
Playground
Code:
fn main() {
let mut gui = GUI { close: false, buttons: vec![Button { text: "".to_string() },Button { text: "".to_string() },Button { text: "".to_string() },Button { text: "".to_string() }] };
gui.handle_input();
}
struct GUI {
close:bool,
buttons: Vec<Button>
}
impl GUI {
pub fn handle_input(&mut self) {
for but in self.buttons.iter_mut() {
but.handle_click(self);
}
}
}
struct Button {
text:String
}
impl Button {
fn handle_click(&mut self, gui:&mut GUI ){
gui.close = true;
}
}
I know that I can not borrow self again because I am iterating mutably over it, but I have no clue how to this different.
I hope you can help me or show me a different way to do this.