Skip to content

Commit

Permalink
[nit] Fix nits in fs.rs.
Browse files Browse the repository at this point in the history
`std::fs::read_to_string` removes unnecessary boilerplate.
  • Loading branch information
ttsugriy committed Feb 19, 2024
1 parent b913e23 commit 9d7729e
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/fs.rs
Expand Up @@ -15,12 +15,10 @@ where
P: AsRef<Path>,
{
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 +42,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 9d7729e

Please sign in to comment.