From fc898e28e28e8e4dfbb8167e61000d3287c3c62e Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 28 Nov 2023 19:18:04 -0500 Subject: [PATCH] Begin converting to new built-in API --- src/built_in_functions/assert.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/built_in_functions/assert.rs diff --git a/src/built_in_functions/assert.rs b/src/built_in_functions/assert.rs new file mode 100644 index 0000000..77ee769 --- /dev/null +++ b/src/built_in_functions/assert.rs @@ -0,0 +1,19 @@ +use crate::{BuiltInFunction, Error, Result, Value}; + +pub struct Assert; + +impl BuiltInFunction for Assert { + fn name(&self) -> &'static str { + "assert" + } + + fn run(&self, arguments: &[Value]) -> Result { + for argument in arguments { + if !argument.as_boolean()? { + return Err(Error::AssertFailed); + } + } + + Ok(Value::Empty) + } +}