Impl new fn CratesToml::write_to_writer

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-22 20:19:04 +10:00
parent 565b404dce
commit 7311f77f29
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -46,6 +46,15 @@ impl CratesToml {
self.write_to_path(Self::default_path()?) self.write_to_path(Self::default_path()?)
} }
pub fn write_to_writer<W: io::Write>(
&self,
mut writer: W,
) -> Result<u64, CratesTomlParseError> {
let data = toml::to_vec(&self)?;
writer.write_all(&data)?;
Ok(data.len().try_into().unwrap())
}
pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<(), CratesTomlParseError> { pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<(), CratesTomlParseError> {
fs::write(path, &toml::to_vec(&self)?)?; fs::write(path, &toml::to_vec(&self)?)?;
Ok(()) Ok(())