mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-24 20:52:56 +00:00
Add new fn Crates2Json::write_to_file
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
1766b92547
commit
d432d54c28
1 changed files with 10 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet},
|
collections::{BTreeMap, BTreeSet},
|
||||||
fs, io,
|
fs,
|
||||||
|
io::{self, Seek},
|
||||||
iter::IntoIterator,
|
iter::IntoIterator,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
@ -70,6 +71,14 @@ impl Crates2Json {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write_to_file(&self, file: &mut fs::File) -> Result<(), Crates2JsonParseError> {
|
||||||
|
self.write_to_writer(&mut *file)?;
|
||||||
|
let pos = file.stream_position()?;
|
||||||
|
file.set_len(pos)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<(), Crates2JsonParseError> {
|
pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<(), Crates2JsonParseError> {
|
||||||
let file = fs::File::create(path.as_ref())?;
|
let file = fs::File::create(path.as_ref())?;
|
||||||
self.write_to_writer(file)
|
self.write_to_writer(file)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue