From fcf5728ddeeb471a89da201de3194ed822c0522b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Wed, 8 Jun 2022 00:54:49 +1200 Subject: [PATCH] Replace Box with String --- src/target.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/target.rs b/src/target.rs index 7f5e4f7b..43b26ccb 100644 --- a/src/target.rs +++ b/src/target.rs @@ -18,13 +18,13 @@ pub const TARGET: &str = env!("TARGET"); /// /// Check [this issue](https://github.com/ryankurte/cargo-binstall/issues/155) /// for more information. -pub async fn detect_targets() -> Vec> { +pub async fn detect_targets() -> Vec { if let Some(target) = get_target_from_rustc().await { let mut v = vec![target]; #[cfg(target_os = "linux")] if v[0].contains("gnu") { - v.push(v[0].replace("gnu", "musl").into_boxed_str()); + v.push(v[0].replace("gnu", "musl")); } #[cfg(target_os = "macos")] @@ -51,7 +51,7 @@ pub async fn detect_targets() -> Vec> { /// Figure out what the host target is using `rustc`. /// If `rustc` is absent, then it would return `None`. -async fn get_target_from_rustc() -> Option> { +async fn get_target_from_rustc() -> Option { let Output { status, stdout, .. } = Command::new("rustc").arg("-vV").output().await.ok()?; if !status.success() { return None; @@ -60,17 +60,14 @@ async fn get_target_from_rustc() -> Option> { Cursor::new(stdout) .lines() .filter_map(|line| line.ok()) - .find_map(|line| { - line.strip_prefix("host: ") - .map(|host| host.to_owned().into_boxed_str()) - }) + .find_map(|line| line.strip_prefix("host: ").map(|host| host.to_owned())) } #[cfg(target_os = "linux")] mod linux { use super::{Command, Output, TARGET}; - pub(super) async fn detect_targets_linux() -> Vec> { + pub(super) async fn detect_targets_linux() -> Vec { let abi = parse_abi(); if let Ok(Output { @@ -123,16 +120,13 @@ mod linux { } } - fn create_target_str(libc_version: &str, abi: &str) -> Box { - let prefix = TARGET.rsplit_once('-').unwrap().0; + fn create_target_str(libc_version: &str, abi: &str) -> String { + let prefix = TARGET + .rsplit_once('-') + .map(|s| format!("{}-", s.0)) + .unwrap_or_default(); - let mut target = String::with_capacity(prefix.len() + 1 + libc_version.len() + abi.len()); - target.push_str(prefix); - target.push('-'); - target.push_str(libc_version); - target.push_str(abi); - - target.into_boxed_str() + format!("{prefix}{libc_version}{abi}") } } @@ -143,7 +137,7 @@ mod macos { pub(super) const AARCH64: &str = "aarch64-apple-darwin"; pub(super) const X86: &str = "x86_64-apple-darwin"; - pub(super) fn detect_targets_macos() -> Vec> { + pub(super) fn detect_targets_macos() -> Vec { if guess_host_triple() == Some(AARCH64) { vec![AARCH64.into(), X86.into()] } else {