From b330a18d40b11fe19dce4b03340814793b9f21e7 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 31 Aug 2022 14:48:15 +1000 Subject: [PATCH] Change typeof `Args::targets` to `Option>` (#327) * Change typeof `Args::targets` to `Option>` Signed-off-by: Jiahao XU --- crates/bin/src/args.rs | 2 +- crates/bin/src/entry.rs | 2 +- crates/detect-targets/src/desired_targets.rs | 4 ++-- crates/detect-targets/src/lib.rs | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/bin/src/args.rs b/crates/bin/src/args.rs index fcaec52f1..aead6a6d3 100644 --- a/crates/bin/src/args.rs +++ b/crates/bin/src/args.rs @@ -60,7 +60,7 @@ pub struct Args { long, value_name = "TRIPLE" )] - pub targets: Option, + pub targets: Option>, /// Override Cargo.toml package manifest path. /// diff --git a/crates/bin/src/entry.rs b/crates/bin/src/entry.rs index 0091b0171..290dc65a1 100644 --- a/crates/bin/src/entry.rs +++ b/crates/bin/src/entry.rs @@ -29,7 +29,7 @@ pub async fn install_crates(mut args: Args, jobserver_client: LazyJobserverClien }; // Launch target detection - let desired_targets = get_desired_targets(args.targets.as_deref()); + let desired_targets = get_desired_targets(args.targets.take()); // Initialize reqwest client let client = create_reqwest_client(args.secure, args.min_tls_version.map(|v| v.into()))?; diff --git a/crates/detect-targets/src/desired_targets.rs b/crates/detect-targets/src/desired_targets.rs index 42acfefd6..c7d7179f1 100644 --- a/crates/detect-targets/src/desired_targets.rs +++ b/crates/detect-targets/src/desired_targets.rs @@ -50,9 +50,9 @@ impl DesiredTargets { /// Since `detect_targets` internally spawns a process and wait for it, /// it's pretty costy, it is recommended to run this fn ASAP and /// reuse the result. -pub fn get_desired_targets(opts_targets: Option<&str>) -> DesiredTargets { +pub fn get_desired_targets(opts_targets: Option>) -> DesiredTargets { if let Some(targets) = opts_targets { - DesiredTargets::initialized(targets.split(',').map(|t| t.to_string()).collect()) + DesiredTargets::initialized(targets) } else { DesiredTargets::auto_detect() } diff --git a/crates/detect-targets/src/lib.rs b/crates/detect-targets/src/lib.rs index 1ba7831bd..6ca2a2976 100644 --- a/crates/detect-targets/src/lib.rs +++ b/crates/detect-targets/src/lib.rs @@ -35,7 +35,10 @@ //! # async fn main() { //! //! assert_eq!( -//! get_desired_targets(Some("x86_64-apple-darwin,aarch64-apple-darwin")).get().await, +//! get_desired_targets(Some(vec![ +//! "x86_64-apple-darwin".to_string(), +//! "aarch64-apple-darwin".to_string(), +//! ])).get().await, //! &["x86_64-apple-darwin", "aarch64-apple-darwin"], //! ); //! # }