Add new fn Crates2Json::write_to_writer

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-22 22:45:55 +10:00
parent 15e2213225
commit 1766b92547
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -65,10 +65,14 @@ impl Crates2Json {
self.write_to_path(Self::default_path()?)
}
pub fn write_to_writer<W: io::Write>(&self, writer: W) -> Result<(), Crates2JsonParseError> {
serde_json::to_writer(writer, &self)?;
Ok(())
}
pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<(), Crates2JsonParseError> {
let file = fs::File::create(path.as_ref())?;
serde_json::to_writer(file, &self)?;
Ok(())
self.write_to_writer(file)
}
pub fn append_to_path<Iter>(