Loading

departments.patch

  1. @@ -30,11 +33,11 @@
  2.                  words.next(); // to (ignored)
  3.                  let department_name = words.next(); // Person’s department
  4.  
  5. -                if person_name != None && department_name != None {
  6. -                    let person_name = person_name.unwrap();
  7. -                    let department_name = department_name.unwrap();
  8. -                    departments.entry(String::from(department_name)).or_insert(Vec::new());
  9. -                    departments.get_mut(department_name).unwrap().push(String::from(person_name));
  10. +                if let (Some(person_name), Some(department_name)) = (person_name, department_name) {
  11. +                    departments
  12. +                        .entry(String::from(department_name))
  13. +                        .or_insert(vec![])
  14. +                        .push(String::from(person_name));
  15.  
  16.                      println!("\n✓ Done.")
  17.                  } else {
  18. @@ -43,7 +46,7 @@
  19.              }
  20.  
  21.              "list" => {
  22. -                for (department_name, employees) in departments.clone() {
  23. +                for (department_name, employees) in &departments {
  24.                      println!("\n{}: ", department_name);
  25.                      for person_name in employees {
  26.                          println!("  - {}", person_name);