From bdf3fa161280f1c7161b6b931e1f58eda482ca6e Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Fri, 23 Aug 2024 12:05:31 +0200 Subject: [PATCH] cleanup: get rid of From/Into for UseCargoMetadata --- src/main.rs | 30 ++++++++++-------------------- src/search_unused.rs | 2 +- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0fc85af..fb4bed9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,22 +20,6 @@ impl UseCargoMetadata { } } -impl From for bool { - fn from(v: UseCargoMetadata) -> bool { - matches!(v, UseCargoMetadata::Yes) - } -} - -impl From 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. @@ -164,12 +148,18 @@ fn run_machete() -> anyhow::Result { } }; + 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 @@ -190,8 +180,8 @@ fn run_machete() -> anyhow::Result { eprintln!("error when handling {}: {}", manifest_path.display(), err); None } - } - }) + }, + ) .collect::>(); // Display all the results. diff --git a/src/search_unused.rs b/src/search_unused.rs index 0c9a217..9f2f93c 100644 --- a/src/search_unused.rs +++ b/src/search_unused.rs @@ -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);