mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 05:28:42 +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)]
|
||||
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
Reference in a new issue