Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: get rid of From/Into<bool> for UseCargoMetadata #131

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading