mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Update Crates2Json::append
to accept iter
instead of one single pair of value. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
6964eee5d1
commit
739b3ee247
1 changed files with 15 additions and 7 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},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,11 +67,13 @@ impl Crates2Json {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_to_path(
|
pub fn append_to_path<Iter>(
|
||||||
path: impl AsRef<Path>,
|
path: impl AsRef<Path>,
|
||||||
cvs: &CrateVersionSource,
|
iter: Iter,
|
||||||
info: CrateInfo,
|
) -> Result<(), Crates2JsonParseError>
|
||||||
) -> Result<(), Crates2JsonParseError> {
|
where
|
||||||
|
Iter: IntoIterator<Item = (CrateVersionSource, CrateInfo)>,
|
||||||
|
{
|
||||||
let mut c2 = match Self::load_from_path(path.as_ref()) {
|
let mut c2 = match Self::load_from_path(path.as_ref()) {
|
||||||
Ok(c2) => c2,
|
Ok(c2) => c2,
|
||||||
Err(Crates2JsonParseError::Io(io_err)) if io_err.kind() == io::ErrorKind::NotFound => {
|
Err(Crates2JsonParseError::Io(io_err)) if io_err.kind() == io::ErrorKind::NotFound => {
|
||||||
|
@ -78,14 +81,19 @@ impl Crates2Json {
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
c2.insert(cvs, info);
|
for (cvs, info) in iter {
|
||||||
|
c2.insert(&cvs, info);
|
||||||
|
}
|
||||||
c2.write_to_path(path.as_ref())?;
|
c2.write_to_path(path.as_ref())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(cvs: &CrateVersionSource, info: CrateInfo) -> Result<(), Crates2JsonParseError> {
|
pub fn append<Iter>(iter: Iter) -> Result<(), Crates2JsonParseError>
|
||||||
Self::append_to_path(Self::default_path()?, cvs, info)
|
where
|
||||||
|
Iter: IntoIterator<Item = (CrateVersionSource, CrateInfo)>,
|
||||||
|
{
|
||||||
|
Self::append_to_path(Self::default_path()?, iter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue