Skip to content

Commit 8409724

Browse files
authored
[nit] Fix nits in fs.rs. (#758)
`std::fs::read_to_string` removes unnecessary boilerplate.
1 parent 42bb780 commit 8409724

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/fs.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use serde::de::DeserializeOwned;
22
use serde::Serialize;
33
use std::ffi::OsStr;
44
use std::fs::{self, File};
5-
use std::io::Read;
65
use std::path::Path;
76
use walkdir::{DirEntry, WalkDir};
87

@@ -15,12 +14,10 @@ where
1514
P: AsRef<Path> + ?Sized,
1615
{
1716
let path = path.as_ref();
18-
let mut f = File::open(path).map_err(|inner| Error::AccessError {
17+
let string = std::fs::read_to_string(path).map_err(|inner| Error::AccessError {
1918
inner,
2019
path: path.to_owned(),
2120
})?;
22-
let mut string = String::new();
23-
let _ = f.read_to_string(&mut string);
2421
let result: A = serde_json::from_str(string.as_str()).map_err(|inner| Error::SerdeError {
2522
inner,
2623
path: path.to_owned(),
@@ -44,8 +41,7 @@ where
4441
fs::create_dir_all(path.as_ref()).map_err(|inner| Error::AccessError {
4542
inner,
4643
path: path.as_ref().to_owned(),
47-
})?;
48-
Ok(())
44+
})
4945
}
5046

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

0 commit comments

Comments
 (0)