mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-04 11:10:02 +00:00
Impl binstall_v1::append_to_path
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
461571075d
commit
f0b6b7b1af
1 changed files with 24 additions and 0 deletions
|
@ -84,3 +84,27 @@ pub enum Error {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
SerdeJsonParse(#[from] serde_json::Error),
|
SerdeJsonParse(#[from] serde_json::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn append_to_path<Iter>(path: impl AsRef<Path>, iter: Iter) -> Result<(), Error>
|
||||||
|
where
|
||||||
|
Iter: IntoIterator<Item = Entry>,
|
||||||
|
{
|
||||||
|
let file = FileLock::new_exclusive(
|
||||||
|
fs::OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.open(path)?,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let writer = io::BufWriter::with_capacity(512, file);
|
||||||
|
|
||||||
|
let mut ser = serde_json::Serializer::new(writer);
|
||||||
|
|
||||||
|
for item in iter {
|
||||||
|
item.serialize(&mut ser)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
ser.into_inner().flush()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue