MCPcopy Create free account
hub / github.com/elastio/devx / touched_crates

Method touched_crates

devx-pre-commit/src/lib.rs:138–149  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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> {

Callers 1

rustfmtMethod · 0.80

Calls 1

staged_rust_filesMethod · 0.80

Tested by

no test coverage detected