Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created May 31, 2018 19:16
Show Gist options
  • Select an option

  • Save Riduidel/4f18283b23ae10d71fa10f18bcdd7643 to your computer and use it in GitHub Desktop.

Select an option

Save Riduidel/4f18283b23ae10d71fa10f18bcdd7643 to your computer and use it in GitHub Desktop.
#[derive(Debug, Copy, Clone)]
struct Cage {
pub sick:i32,
pub healthy:i32,
pub alive:i32
}
impl Cage {
pub fn derive(self)->Cage {
//...
}
}
fn main() {
//...
let mut cages:Vec<Cage> = vec![];
//...
for year in 0..y {
// The iter pattern is explained at https://stackoverflow.com/a/30026986/15619
// In quite an un-intuitive way, to have map working, the struct must derive Copy and Clone
// To have references copiable (see https://stackoverflow.com/a/28527789/15619)
let mut next_cages:Vec<Cage> = cages.iter().map(|c| c.derive()).collect();
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment