Skip to content

Commit

Permalink
[nit] Fix nits in fs.rs. (#758)
Browse files Browse the repository at this point in the history
`std::fs::read_to_string` removes unnecessary boilerplate.
  • Loading branch information
ttsugriy committed Jul 27, 2024
1 parent 42bb780 commit 8409724
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use serde::de::DeserializeOwned;
use serde::Serialize;
use std::ffi::OsStr;
use std::fs::{self, File};
use std::io::Read;
use std::path::Path;
use walkdir::{DirEntry, WalkDir};

Expand All @@ -15,12 +14,10 @@ where
P: AsRef<Path> + ?Sized,
{
let path = path.as_ref();
let mut f = File::open(path).map_err(|inner| Error::AccessError {
let string = std::fs::read_to_string(path).map_err(|inner| Error::AccessError {
inner,
path: path.to_owned(),
})?;
let mut string = String::new();
let _ = f.read_to_string(&mut string);
let result: A = serde_json::from_str(string.as_str()).map_err(|inner| Error::SerdeError {
inner,
path: path.to_owned(),
Expand All @@ -44,8 +41,7 @@ where
fs::create_dir_all(path.as_ref()).map_err(|inner| Error::AccessError {
inner,
path: path.as_ref().to_owned(),
})?;
Ok(())
})
}

pub fn cp(from: &Path, to: &Path) -> Result<()> {
Expand Down

0 comments on commit 8409724

Please sign in to comment.