mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-13 15:30: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
|
@ -6,6 +6,7 @@ use std::{
|
|||
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<String, Vec<String>>,
|
||||
v1: BTreeMap<String, Vec<CompactString>>,
|
||||
}
|
||||
|
||||
impl CratesToml {
|
||||
|
@ -38,7 +39,7 @@ impl CratesToml {
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ impl CratesToml {
|
|||
iter: Iter,
|
||||
) -> Result<(), CratesTomlParseError>
|
||||
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 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<Item = (&'a CrateVersionSource, Vec<String>)>,
|
||||
Iter: IntoIterator<Item = (&'a CrateVersionSource, Vec<CompactString>)>,
|
||||
{
|
||||
Self::append_to_path(Self::default_path()?, iter)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue