refactored unwrap calls to make it more stable

This commit is contained in:
euzu
2025-07-22 11:32:46 +02:00
parent 7ef30e1aae
commit 6c238c607f
44 changed files with 560 additions and 479 deletions
+4 -3
View File
@@ -71,9 +71,10 @@ where
self.dfs_find_cycles(neighbor, visited, recursion_stack, cycles);
} else if recursion_stack.contains(neighbor) {
// Cycle detected; collect the cycle path
let cycle_start_index = recursion_stack.iter().position(|n| n == neighbor).unwrap();
let cycle = recursion_stack[cycle_start_index..].to_vec();
cycles.push(cycle);
if let Some(cycle_start_index) = recursion_stack.iter().position(|n| n == neighbor) {
let cycle = recursion_stack[cycle_start_index..].to_vec();
cycles.push(cycle);
}
}
}
}