Skip to content

Instantly share code, notes, and snippets.

@Verdagon
Created April 7, 2022 00:56
Show Gist options
  • Save Verdagon/225b3d4b646530294fcb6fea91c6991a to your computer and use it in GitHub Desktop.
Save Verdagon/225b3d4b646530294fcb6fea91c6991a to your computer and use it in GitHub Desktop.
struct Account {
name: String,
money: i64,
labelView: i32
}
struct Button {
onclick: Box<dyn FnMut()>
}
fn main() {
// Make some accounts.
let mut accounts = vec![
Account { name: "Bob".to_string(), money: 100, labelView: 0 },
Account { name: "Cindy".to_string(), money: 100, labelView: 0 },
Account { name: "Reginald".to_string(), money: 100, labelView: 0 },
Account { name: "Jim Argalax".to_string(), money: 100, labelView: 0 },
Account { name: "Valerian Vast".to_string(), money: 100, labelView: 0 },
Account { name: "Archonicus Auriarch".to_string(), money: 100, labelView: 0 }
];
let mut page = Vec::new();
for mut account in &mut accounts {
let button = Button { onclick: Box::new(|| {
account.money = account.money + 10;
})};
page.push(button);
}
page.push(Button { onclick: Box::new(|| {
for mut account in &mut accounts {
account.money = account.money + 10;
}
})});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment