Created
May 31, 2018 19:16
-
-
Save Riduidel/4f18283b23ae10d71fa10f18bcdd7643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[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