diff --git a/Cargo.lock b/Cargo.lock index 565442da..ba311b77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,7 @@ dependencies = [ "bzip2", "cargo_toml", "clap", + "compact_str", "crates_io_api", "dirs", "embed-resource", @@ -173,6 +174,15 @@ dependencies = [ "toml", ] +[[package]] +name = "castaway" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a17ed5635fc8536268e5d4de1e22e81ac34419e5f052d4d51f4e01dcc263fcc" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.0.73" @@ -257,6 +267,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "compact_str" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5857fc4f27cd0fa2cd7c4a4fa780c0da3d898ae27e66bf6a719343e219e9a559" +dependencies = [ + "castaway", + "itoa", + "ryu", + "serde", +] + [[package]] name = "core-foundation" version = "0.9.3" diff --git a/Cargo.toml b/Cargo.toml index 7b8df205..410d4a13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ bytes = "1.2.0" bzip2 = "0.4.3" cargo_toml = "0.11.5" clap = { version = "3.2.14", features = ["derive"] } +compact_str = { version = "0.5.2", features = ["serde"] } crates_io_api = { version = "0.8.0", default-features = false } dirs = "4.0.0" flate2 = { version = "1.0.24", default-features = false } diff --git a/src/bins.rs b/src/bins.rs index d08cf15a..7240707a 100644 --- a/src/bins.rs +++ b/src/bins.rs @@ -1,13 +1,14 @@ use std::path::{Path, PathBuf}; use cargo_toml::Product; +use compact_str::CompactString; use log::debug; use serde::Serialize; use crate::{atomic_install, atomic_symlink_file, BinstallError, PkgFmt, PkgMeta, Template}; pub struct BinFile { - pub base_name: String, + pub base_name: CompactString, pub source: PathBuf, pub dest: PathBuf, pub link: PathBuf, @@ -15,7 +16,7 @@ pub struct BinFile { impl BinFile { pub fn from_product(data: &Data, product: &Product) -> Result { - let base_name = product.name.clone().unwrap(); + let base_name = CompactString::from(product.name.clone().unwrap()); let binary_ext = if data.target.contains("windows") { ".exe" diff --git a/src/binstall.rs b/src/binstall.rs index 63eb70b8..f28c0e5d 100644 --- a/src/binstall.rs +++ b/src/binstall.rs @@ -1,6 +1,7 @@ -use std::collections::BTreeSet; use std::path::PathBuf; +use compact_str::CompactString; + use crate::{metafiles, DesiredTargets, PkgOverride}; mod resolve; @@ -20,7 +21,7 @@ pub struct Options { /// MetaData required to update MetaFiles. pub struct MetaData { - pub bins: BTreeSet, + pub bins: Vec, pub cvs: metafiles::CrateVersionSource, pub version_req: String, pub target: String, diff --git a/src/metafiles/v1.rs b/src/metafiles/v1.rs index b91f715a..374188ba 100644 --- a/src/metafiles/v1.rs +++ b/src/metafiles/v1.rs @@ -1,11 +1,12 @@ use std::{ - collections::{BTreeMap, BTreeSet}, + collections::BTreeMap, fs::File, io::{self, Seek}, iter::IntoIterator, path::{Path, PathBuf}, }; +use compact_str::CompactString; use miette::Diagnostic; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -15,7 +16,7 @@ use crate::{cargo_home, create_if_not_exist, FileLock}; #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct CratesToml { - v1: BTreeMap>, + v1: BTreeMap>, } impl CratesToml { @@ -38,7 +39,7 @@ impl CratesToml { Self::load_from_reader(file) } - pub fn insert(&mut self, cvs: &CrateVersionSource, bins: BTreeSet) { + pub fn insert(&mut self, cvs: &CrateVersionSource, bins: Vec) { self.v1.insert(cvs.to_string(), bins); } @@ -70,7 +71,7 @@ impl CratesToml { iter: Iter, ) -> Result<(), CratesTomlParseError> where - Iter: IntoIterator)>, + Iter: IntoIterator)>, { let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?; let mut c1 = Self::load_from_reader(&mut *file)?; @@ -87,7 +88,7 @@ impl CratesToml { pub fn append<'a, Iter>(iter: Iter) -> Result<(), CratesTomlParseError> where - Iter: IntoIterator)>, + Iter: IntoIterator)>, { Self::append_to_path(Self::default_path()?, iter) }