oneline_template/functions/int/
abs.rs

1use crate::function_executor::*;
2
3/// Function: `int:abs`
4/// 
5/// Input: `int`
6///
7/// Returns `uint`
8pub struct Abs;
9
10impl FunctionExecutor for Abs {
11    fn schema(&self) -> FunctionSchema {
12        FunctionSchema::new("int:abs")
13    }
14
15    fn call(&self, value: Value, _arguments: &[Value]) -> Result<Value, FunctionError> {
16        let value = value.as_int()?;
17        let value = value.abs() as u128;
18        let value = Value::UInt(value);
19        return Ok(value);
20    }
21}