Finds all child directories in the given directory. For each directory, tries to parse its name as an integer. Returns the maximum found successfully parsed integer or [`None`] if no integer was found.
(directory: &Path)
| 105 | /// For each directory, tries to parse its name as an integer. |
| 106 | /// Returns the maximum found successfully parsed integer or [`None`] if no integer was found. |
| 107 | fn find_max_id_in_dir(directory: &Path) -> Option<u64> { |
| 108 | if let Ok(entries) = std::fs::read_dir(directory) { |
| 109 | entries |
| 110 | .filter_map(|entry| { |
| 111 | entry.ok().and_then(|entry| { |
| 112 | match entry.metadata().ok().map(|m| m.is_dir()).unwrap_or(false) { |
| 113 | true => entry |
| 114 | .file_name() |
| 115 | .to_str() |
| 116 | .and_then(|f| f.parse::<u64>().ok()), |
| 117 | false => None, |
| 118 | } |
| 119 | }) |
| 120 | }) |
| 121 | .max() |
| 122 | } else { |
| 123 | None |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | fn create_new_server_dir(directory: &Path) -> crate::Result<PathBuf> { |
| 128 | let max_id = find_max_id_in_dir(directory).unwrap_or(0); |
no test coverage detected