1
0
This commit is contained in:
Jeff 2023-11-28 18:28:07 -05:00
parent b46dfc5791
commit a1f3dcb107
2 changed files with 8 additions and 2 deletions

View File

@ -14,7 +14,7 @@ impl BuiltInFunction for Read {
} }
fn run(&self, arguments: &[Value]) -> Result<Value> { fn run(&self, arguments: &[Value]) -> Result<Value> {
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); let path = PathBuf::from(path_string);
if path.is_dir() { if path.is_dir() {
@ -56,7 +56,7 @@ impl BuiltInFunction for Write {
} }
fn run(&self, arguments: &[Value]) -> Result<Value> { fn run(&self, arguments: &[Value]) -> Result<Value> {
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()?; let path = arguments.get(1).unwrap_or(&Value::Empty).as_string()?;
write(path, file_content)?; write(path, file_content)?;

View File

@ -223,6 +223,12 @@ impl Value {
} }
} }
impl Default for &Value {
fn default() -> Self {
&Value::Empty
}
}
impl Add for Value { impl Add for Value {
type Output = Result<Value>; type Output = Result<Value>;