From a52ac3fc7a9cdac53819b80bd9e27664226abaf9 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 2 Aug 2022 22:26:24 +1000 Subject: [PATCH 1/3] Use `CompactString` for `Options::version_req` which is unlikely to be larger than 24 bytes. Signed-off-by: Jiahao XU --- src/binstall.rs | 4 +++- src/main.rs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/binstall.rs b/src/binstall.rs index c6fcc569..12a532f7 100644 --- a/src/binstall.rs +++ b/src/binstall.rs @@ -1,5 +1,7 @@ use std::path::PathBuf; +use compact_str::CompactString; + use crate::{metafiles::binstall_v1::MetaData, DesiredTargets, PkgOverride}; mod resolve; @@ -11,7 +13,7 @@ pub use install::*; pub struct Options { pub no_symlinks: bool, pub dry_run: bool, - pub version: Option, + pub version: Option, pub manifest_path: Option, pub cli_overrides: PkgOverride, pub desired_targets: DesiredTargets, diff --git a/src/main.rs b/src/main.rs index ccbc519a..61d9c86f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use std::{ }; use clap::{AppSettings, Parser}; +use compact_str::CompactString; use log::{debug, error, info, warn, LevelFilter}; use miette::{miette, Result, WrapErr}; use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode}; @@ -42,7 +43,7 @@ struct Options { /// Cannot be used when multiple packages are installed at once, use the attached version /// syntax in that case. #[clap(help_heading = "Package selection", long = "version")] - version_req: Option, + version_req: Option, /// Override binary target set. /// From f72eafb049416d0fd9f1f9d2f3fbc90a9a67abae Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 2 Aug 2022 22:28:44 +1000 Subject: [PATCH 2/3] Use `PathBuf` for field `Options::install_path` Since it does not require a utf-8 string. Signed-off-by: Jiahao XU --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 61d9c86f..b1fba258 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,7 @@ struct Options { /// switches over to a "local" install, where binaries are installed at the path given, and the /// global metadata files are not updated. #[clap(help_heading = "Options", long)] - install_path: Option, + install_path: Option, /// Enforce downloads over secure transports only. /// From 60d17c7e5654ad6cbd6a55bf4df6f73c4991fd2c Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 2 Aug 2022 22:42:05 +1000 Subject: [PATCH 3/3] Ret `CompactString` in `Fetcher::source_name` Signed-off-by: Jiahao XU --- src/fetchers.rs | 3 ++- src/fetchers/gh_crate_meta.rs | 11 ++++++----- src/fetchers/quickinstall.rs | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/fetchers.rs b/src/fetchers.rs index 16691707..952b90fe 100644 --- a/src/fetchers.rs +++ b/src/fetchers.rs @@ -1,6 +1,7 @@ use std::path::Path; use std::sync::Arc; +use compact_str::CompactString; pub use gh_crate_meta::*; pub use log::debug; pub use quickinstall::*; @@ -35,7 +36,7 @@ pub trait Fetcher: Send + Sync { fn pkg_fmt(&self) -> PkgFmt; /// A short human-readable name or descriptor for the package source - fn source_name(&self) -> String; + fn source_name(&self) -> CompactString; /// Should return true if the remote is from a third-party source fn is_third_party(&self) -> bool; diff --git a/src/fetchers/gh_crate_meta.rs b/src/fetchers/gh_crate_meta.rs index 7a4381db..6375d7df 100644 --- a/src/fetchers/gh_crate_meta.rs +++ b/src/fetchers/gh_crate_meta.rs @@ -1,6 +1,7 @@ use std::path::Path; use std::sync::Arc; +use compact_str::{CompactString, ToCompactString}; use log::{debug, info, warn}; use once_cell::sync::OnceCell; use reqwest::Client; @@ -79,19 +80,19 @@ impl super::Fetcher for GhCrateMeta { self.data.meta.pkg_fmt } - fn source_name(&self) -> String { + fn source_name(&self) -> CompactString { self.url .get() .map(|url| { if let Some(domain) = url.domain() { - domain.to_string() + domain.to_compact_string() } else if let Some(host) = url.host_str() { - host.to_string() + host.to_compact_string() } else { - url.to_string() + url.to_compact_string() } }) - .unwrap_or_else(|| "invalid url".to_string()) + .unwrap_or_else(|| "invalid url".into()) } fn is_third_party(&self) -> bool { diff --git a/src/fetchers/quickinstall.rs b/src/fetchers/quickinstall.rs index bdca2762..f79b9bc1 100644 --- a/src/fetchers/quickinstall.rs +++ b/src/fetchers/quickinstall.rs @@ -1,6 +1,7 @@ use std::path::Path; use std::sync::Arc; +use compact_str::CompactString; use log::{debug, info}; use reqwest::Client; use reqwest::Method; @@ -49,8 +50,8 @@ impl super::Fetcher for QuickInstall { PkgFmt::Tgz } - fn source_name(&self) -> String { - String::from("QuickInstall") + fn source_name(&self) -> CompactString { + CompactString::from("QuickInstall") } fn is_third_party(&self) -> bool {