From a1f3dcb1076b068b7f351e8e5c67ce9b0ec3f779 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 28 Nov 2023 18:28:07 -0500 Subject: [PATCH] Clean up --- src/built_in_functions/fs.rs | 4 ++-- src/value/mod.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/built_in_functions/fs.rs b/src/built_in_functions/fs.rs index 94b2dbd..d5f393f 100644 --- a/src/built_in_functions/fs.rs +++ b/src/built_in_functions/fs.rs @@ -14,7 +14,7 @@ impl BuiltInFunction for Read { } fn run(&self, arguments: &[Value]) -> Result { - let path_string = arguments.first().unwrap_or(&Value::Empty).as_string()?; + let path_string = arguments.first().unwrap_or_default().as_string()?; let path = PathBuf::from(path_string); if path.is_dir() { @@ -56,7 +56,7 @@ impl BuiltInFunction for Write { } fn run(&self, arguments: &[Value]) -> Result { - let file_content = arguments.first().unwrap_or(&Value::Empty).as_string()?; + let file_content = arguments.first().unwrap_or_default().as_string()?; let path = arguments.get(1).unwrap_or(&Value::Empty).as_string()?; write(path, file_content)?; diff --git a/src/value/mod.rs b/src/value/mod.rs index 656b21e..eafa212 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -223,6 +223,12 @@ impl Value { } } +impl Default for &Value { + fn default() -> Self { + &Value::Empty + } +} + impl Add for Value { type Output = Result;