oneline_template/functions/bool/
unwrap_or.rs

1use crate::function_executor::*;
2
3/// Function: `bool:unwrap_or`
4/// 
5/// Input: `Option<bool>`
6///
7/// * first argument: default bool
8///
9/// Returns `bool`
10pub struct UnwrapOr;
11
12impl FunctionExecutor for UnwrapOr {
13    fn schema(&self) -> FunctionSchema {
14        FunctionSchema::new("bool:unwrap_or")
15            .with_argument(FunctionArgument::bool())
16    }
17
18    fn call(&self, value: Value, arguments: &[Value]) -> Result<Value, FunctionError> {
19        let value = value.into_option()?;
20        let value = match value {
21            Some(value) => {
22                value.into_bool()?
23            },
24            None => {
25                arguments[0].as_bool()?.clone()
26            },
27        };
28        let value = Value::Bool(value);
29        return Ok(value);
30    }
31}