mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 21:48:42 +00:00
Fix CratesToml::write_to_{writer, file}
Make them consistent with `Crates2Json::write_to_{writer, file}` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
0a753f3e4b
commit
6ce48419b6
1 changed files with 5 additions and 7 deletions
|
@ -47,18 +47,16 @@ impl CratesToml {
|
||||||
self.write_to_path(Self::default_path()?)
|
self.write_to_path(Self::default_path()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_writer<W: io::Write>(
|
pub fn write_to_writer<W: io::Write>(&self, mut writer: W) -> Result<(), CratesTomlParseError> {
|
||||||
&self,
|
|
||||||
mut writer: W,
|
|
||||||
) -> Result<u64, CratesTomlParseError> {
|
|
||||||
let data = toml::to_vec(&self)?;
|
let data = toml::to_vec(&self)?;
|
||||||
writer.write_all(&data)?;
|
writer.write_all(&data)?;
|
||||||
Ok(data.len().try_into().unwrap())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_file(&self, file: &mut fs::File) -> Result<(), CratesTomlParseError> {
|
pub fn write_to_file(&self, file: &mut fs::File) -> Result<(), CratesTomlParseError> {
|
||||||
let cnt = self.write_to_writer(&mut *file)?;
|
self.write_to_writer(&mut *file)?;
|
||||||
file.set_len(cnt)?;
|
let pos = file.stream_position()?;
|
||||||
|
file.set_len(pos)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue