Returns the names of the crates that contain [`Self::staged_rust_files()`]. Warning: this heuristically looks for `Cargo.toml` files and searches for `name = "` substring in them to get the crate name (i.e. it doesn't really parse them properly, but this works 99% of the time and lets us save on a full-fledged toml parser dependency). This heuristic may be relaxed in the future, and it shouldn't
(&self)
| 136 | /// This heuristic may be relaxed in the future, and it shouldn't be considered a |
| 137 | /// breaking change. |
| 138 | pub fn touched_crates(&self) -> HashSet<String> { |
| 139 | self.staged_rust_files() |
| 140 | .filter_map(|rust_file_path| { |
| 141 | rust_file_path.ancestors().find_map(|candidate| { |
| 142 | let cargo_toml = self.project_root.join(candidate).join("Cargo.toml"); |
| 143 | let cargo_toml = fs::read_to_string(&cargo_toml).ok()?; |
| 144 | |
| 145 | Self::parse_crate_name(&cargo_toml) |
| 146 | }) |
| 147 | }) |
| 148 | .collect() |
| 149 | } |
| 150 | |
| 151 | /// Returns an iterator over all staged files with `.rs` extension. |
| 152 | pub fn staged_rust_files(&self) -> impl Iterator<Item = &Path> { |
no test coverage detected