mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Update CratesToml::append
to accept iter
intead of one single pair of value. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
739b3ee247
commit
488e7b8492
1 changed files with 15 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet},
|
collections::{BTreeMap, BTreeSet},
|
||||||
fs, io,
|
fs, io,
|
||||||
|
iter::IntoIterator,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
@ -44,11 +45,13 @@ impl CratesToml {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_to_path(
|
pub fn append_to_path<'a, Iter>(
|
||||||
path: impl AsRef<Path>,
|
path: impl AsRef<Path>,
|
||||||
cvs: &CrateVersionSource,
|
iter: Iter,
|
||||||
bins: BTreeSet<String>,
|
) -> Result<(), CratesTomlParseError>
|
||||||
) -> Result<(), CratesTomlParseError> {
|
where
|
||||||
|
Iter: IntoIterator<Item = (&'a CrateVersionSource, BTreeSet<String>)>,
|
||||||
|
{
|
||||||
let mut c1 = match Self::load_from_path(path.as_ref()) {
|
let mut c1 = match Self::load_from_path(path.as_ref()) {
|
||||||
Ok(c1) => c1,
|
Ok(c1) => c1,
|
||||||
Err(CratesTomlParseError::Io(io_err)) if io_err.kind() == io::ErrorKind::NotFound => {
|
Err(CratesTomlParseError::Io(io_err)) if io_err.kind() == io::ErrorKind::NotFound => {
|
||||||
|
@ -56,17 +59,19 @@ impl CratesToml {
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
c1.insert(cvs, bins);
|
for (cvs, bins) in iter {
|
||||||
|
c1.insert(cvs, bins);
|
||||||
|
}
|
||||||
c1.write_to_path(path.as_ref())?;
|
c1.write_to_path(path.as_ref())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(
|
pub fn append<'a, Iter>(iter: Iter) -> Result<(), CratesTomlParseError>
|
||||||
cvs: &CrateVersionSource,
|
where
|
||||||
bins: BTreeSet<String>,
|
Iter: IntoIterator<Item = (&'a CrateVersionSource, BTreeSet<String>)>,
|
||||||
) -> Result<(), CratesTomlParseError> {
|
{
|
||||||
Self::append_to_path(Self::default_path()?, cvs, bins)
|
Self::append_to_path(Self::default_path()?, iter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue