Skip to content

Commit

Permalink
cleanup: get rid of From/Into<bool> for UseCargoMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Aug 23, 2024
1 parent 711b955 commit bdf3fa1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
30 changes: 10 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ impl UseCargoMetadata {
}
}

impl From<UseCargoMetadata> for bool {
fn from(v: UseCargoMetadata) -> bool {
matches!(v, UseCargoMetadata::Yes)
}
}

impl From<bool> for UseCargoMetadata {
fn from(b: bool) -> Self {
if b {
Self::Yes
} else {
Self::No
}
}
}

#[derive(argh::FromArgs)]
#[argh(description = r#"
cargo-machete: Helps find unused dependencies in a fast yet imprecise way.
Expand Down Expand Up @@ -164,12 +148,18 @@ fn run_machete() -> anyhow::Result<bool> {
}
};

let with_metadata = if args.with_metadata {
UseCargoMetadata::Yes
} else {
UseCargoMetadata::No
};

// Run analysis in parallel. This will spawn new rayon tasks when dependencies are effectively
// used by any Rust crate.
let results = manifest_path_entries
.par_iter()
.filter_map(|manifest_path| {
match find_unused(manifest_path, args.with_metadata.into()) {
.filter_map(
|manifest_path| match find_unused(manifest_path, with_metadata) {
Ok(Some(analysis)) => {
if analysis.unused.is_empty() {
None
Expand All @@ -190,8 +180,8 @@ fn run_machete() -> anyhow::Result<bool> {
eprintln!("error when handling {}: {}", manifest_path.display(), err);
None
}
}
})
},
)
.collect::<Vec<_>>();

// Display all the results.
Expand Down
2 changes: 1 addition & 1 deletion src/search_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub(crate) fn find_unused(
package_name.clone(),
manifest_path,
manifest,
with_cargo_metadata.into(),
matches!(with_cargo_metadata, UseCargoMetadata::Yes),
)?;

let paths = collect_paths(&dir_path, &analysis);
Expand Down

0 comments on commit bdf3fa1

Please sign in to comment.