From cd04dadb4b4aa174fd8c6b9ba4abda417aba9799 Mon Sep 17 00:00:00 2001 From: Lucy Date: Sat, 5 Oct 2024 22:46:09 -0400 Subject: [PATCH] Some more code cleanup --- crates/file/src/lib.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/file/src/lib.rs b/crates/file/src/lib.rs index 59b77fe..f887c16 100644 --- a/crates/file/src/lib.rs +++ b/crates/file/src/lib.rs @@ -32,10 +32,8 @@ pub fn file_read(path: PathBuf) -> Option { #[byond_fn] pub fn file_write(path: PathBuf, data: String) -> bool { let file_write_impl = || -> Option<()> { - if let Some(parent) = path.parent() { - if !parent.exists() { - std::fs::create_dir_all(parent).ok()?; - } + if let Some(parent) = path.parent().filter(|parent| !parent.exists()) { + std::fs::create_dir_all(parent).ok()?; } let mut file = File::create(path).ok().map(BufWriter::new)?; file.write_all(data.as_bytes()).ok()?; @@ -49,10 +47,8 @@ pub fn file_write(path: PathBuf, data: String) -> bool { #[byond_fn] pub fn file_append(path: PathBuf, data: String) -> bool { let file_append_impl = || -> Option<()> { - if let Some(parent) = path.parent() { - if !parent.exists() { - std::fs::create_dir_all(parent).ok()?; - } + if let Some(parent) = path.parent().filter(|parent| !parent.exists()) { + std::fs::create_dir_all(parent).ok()?; } let mut file = OpenOptions::new() .create(true)