Skip to content

Commit

Permalink
Some more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Oct 6, 2024
1 parent b182582 commit cd04dad
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/file/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ pub fn file_read(path: PathBuf) -> Option<String> {
#[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()?;
Expand All @@ -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)
Expand Down

0 comments on commit cd04dad

Please sign in to comment.