Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- enum Relationship {
- PARENT,
- CHILD,
- }
- #[derive(Debug)]
- struct Person {
- relationship: Relationship,
- name: String,
- age: u8,
- }
- impl Person {
- fn new(relationship: Relationship, name: &str, age: u8) -> Person {
- Person {
- relationship,
- name: name.to_string(),
- age,
- }
- }
- }
- fn main() {
- let mut persons = vec![
- Person::new(Relationship::PARENT, "foo", 65),
- Person::new(Relationship::CHILD, "foo jr", 25),
- Person::new(Relationship::PARENT, "bar", 50),
- Person::new(Relationship::CHILD, "bar jr", 20),
- ];
- for i in 0..(persons.len() - 1) {
- let mut first = persons.get_mut(i).unwrap();
- let mut second = persons.get_mut(i+1).unwrap();
- first.age /= 5;
- second.age += 1;
- }
- println!("{:?}", persons);
- }
Add Comment
Please, Sign In to add comment