loop -> while let
authorGrégory Burri <gregory.burri@matisa.ch>
Mon, 9 Dec 2019 13:57:57 +0000 (14:57 +0100)
committerGrégory Burri <gregory.burri@matisa.ch>
Mon, 9 Dec 2019 13:57:57 +0000 (14:57 +0100)
src/day06.rs

index 1923336..fddb899 100644 (file)
@@ -17,11 +17,9 @@ fn parents<'a>(orbits: &'a Orbits, planet: &str) -> Vec<&'a str> {
     let mut parents = Vec::<&str>::new();
     let mut current_planet = planet;
 
-    loop {
-        match orbits.get(current_planet) {
-            Some (parent) => { parents.insert(0, parent); current_planet = parent; },
-            None => break
-        }
+    while let Some (parent) = orbits.get(current_planet) {
+        parents.insert(0, parent);
+        current_planet = parent;
     }
 
     parents