mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-04 03:00:03 +00:00
Optimize CratesToml
: Use CompactString
for bins
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
834b8bb9c5
commit
2dc246c392
3 changed files with 11 additions and 7 deletions
|
@ -1,13 +1,14 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use cargo_toml::Product;
|
use cargo_toml::Product;
|
||||||
|
use compact_str::CompactString;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{atomic_install, atomic_symlink_file, BinstallError, PkgFmt, PkgMeta, Template};
|
use crate::{atomic_install, atomic_symlink_file, BinstallError, PkgFmt, PkgMeta, Template};
|
||||||
|
|
||||||
pub struct BinFile {
|
pub struct BinFile {
|
||||||
pub base_name: String,
|
pub base_name: CompactString,
|
||||||
pub source: PathBuf,
|
pub source: PathBuf,
|
||||||
pub dest: PathBuf,
|
pub dest: PathBuf,
|
||||||
pub link: PathBuf,
|
pub link: PathBuf,
|
||||||
|
@ -15,7 +16,7 @@ pub struct BinFile {
|
||||||
|
|
||||||
impl BinFile {
|
impl BinFile {
|
||||||
pub fn from_product(data: &Data, product: &Product) -> Result<Self, BinstallError> {
|
pub fn from_product(data: &Data, product: &Product) -> Result<Self, BinstallError> {
|
||||||
let base_name = product.name.clone().unwrap();
|
let base_name = CompactString::from(product.name.clone().unwrap());
|
||||||
|
|
||||||
let binary_ext = if data.target.contains("windows") {
|
let binary_ext = if data.target.contains("windows") {
|
||||||
".exe"
|
".exe"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use compact_str::CompactString;
|
||||||
|
|
||||||
use crate::{metafiles, DesiredTargets, PkgOverride};
|
use crate::{metafiles, DesiredTargets, PkgOverride};
|
||||||
|
|
||||||
mod resolve;
|
mod resolve;
|
||||||
|
@ -19,7 +21,7 @@ pub struct Options {
|
||||||
|
|
||||||
/// MetaData required to update MetaFiles.
|
/// MetaData required to update MetaFiles.
|
||||||
pub struct MetaData {
|
pub struct MetaData {
|
||||||
pub bins: Vec<String>,
|
pub bins: Vec<CompactString>,
|
||||||
pub cvs: metafiles::CrateVersionSource,
|
pub cvs: metafiles::CrateVersionSource,
|
||||||
pub version_req: String,
|
pub version_req: String,
|
||||||
pub target: String,
|
pub target: String,
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use compact_str::CompactString;
|
||||||
use miette::Diagnostic;
|
use miette::Diagnostic;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -15,7 +16,7 @@ use crate::{cargo_home, create_if_not_exist, FileLock};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
pub struct CratesToml {
|
pub struct CratesToml {
|
||||||
v1: BTreeMap<String, Vec<String>>,
|
v1: BTreeMap<String, Vec<CompactString>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CratesToml {
|
impl CratesToml {
|
||||||
|
@ -38,7 +39,7 @@ impl CratesToml {
|
||||||
Self::load_from_reader(file)
|
Self::load_from_reader(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, cvs: &CrateVersionSource, bins: Vec<String>) {
|
pub fn insert(&mut self, cvs: &CrateVersionSource, bins: Vec<CompactString>) {
|
||||||
self.v1.insert(cvs.to_string(), bins);
|
self.v1.insert(cvs.to_string(), bins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ impl CratesToml {
|
||||||
iter: Iter,
|
iter: Iter,
|
||||||
) -> Result<(), CratesTomlParseError>
|
) -> Result<(), CratesTomlParseError>
|
||||||
where
|
where
|
||||||
Iter: IntoIterator<Item = (&'a CrateVersionSource, Vec<String>)>,
|
Iter: IntoIterator<Item = (&'a CrateVersionSource, Vec<CompactString>)>,
|
||||||
{
|
{
|
||||||
let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?;
|
let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?;
|
||||||
let mut c1 = Self::load_from_reader(&mut *file)?;
|
let mut c1 = Self::load_from_reader(&mut *file)?;
|
||||||
|
@ -87,7 +88,7 @@ impl CratesToml {
|
||||||
|
|
||||||
pub fn append<'a, Iter>(iter: Iter) -> Result<(), CratesTomlParseError>
|
pub fn append<'a, Iter>(iter: Iter) -> Result<(), CratesTomlParseError>
|
||||||
where
|
where
|
||||||
Iter: IntoIterator<Item = (&'a CrateVersionSource, Vec<String>)>,
|
Iter: IntoIterator<Item = (&'a CrateVersionSource, Vec<CompactString>)>,
|
||||||
{
|
{
|
||||||
Self::append_to_path(Self::default_path()?, iter)
|
Self::append_to_path(Self::default_path()?, iter)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue