mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Add new fn CratesToml::write_to_file
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
05115641ff
commit
e1b6fb85aa
1 changed files with 8 additions and 1 deletions
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||
use thiserror::Error;
|
||||
|
||||
use super::CrateVersionSource;
|
||||
use crate::cargo_home;
|
||||
use crate::{cargo_home, create_if_not_exist, FileLock};
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct CratesToml {
|
||||
|
@ -55,6 +55,13 @@ impl CratesToml {
|
|||
Ok(data.len().try_into().unwrap())
|
||||
}
|
||||
|
||||
pub fn write_to_file(&self, file: &mut fs::File) -> Result<(), CratesTomlParseError> {
|
||||
let cnt = self.write_to_writer(&mut *file)?;
|
||||
file.set_len(cnt)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<(), CratesTomlParseError> {
|
||||
fs::write(path, &toml::to_vec(&self)?)?;
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Reference in a new issue