From 8409724efad25c8f18a850ea0324e79e0794e61e Mon Sep 17 00:00:00 2001 From: Taras Tsugrii Date: Sat, 27 Jul 2024 00:56:55 -0700 Subject: [PATCH] [nit] Fix nits in fs.rs. (#758) `std::fs::read_to_string` removes unnecessary boilerplate. --- src/fs.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index dcf26358..98badbc5 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -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}; @@ -15,12 +14,10 @@ where P: AsRef + ?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(), @@ -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<()> {