mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-13 15:30:03 +00:00
Refactor: Extract Crates2Json::append{_to_path}
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
0157a594e6
commit
1e725a9ffe
2 changed files with 28 additions and 16 deletions
|
@ -63,6 +63,22 @@ impl Crates2Json {
|
|||
fs::write(path, &serde_json::to_vec(&self)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn append_to_path(
|
||||
path: impl AsRef<Path>,
|
||||
cvs: CrateVersionSource,
|
||||
info: CrateInfo,
|
||||
) -> Result<(), Crates2JsonParseError> {
|
||||
let mut c2 = Self::load_from_path(path.as_ref()).unwrap_or_default();
|
||||
c2.insert(cvs, info);
|
||||
c2.write_to_path(path.as_ref())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn append(cvs: CrateVersionSource, info: CrateInfo) -> Result<(), Crates2JsonParseError> {
|
||||
Self::append_to_path(Self::default_path()?, cvs, info)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Diagnostic, Error)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue