1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::collections::HashMap;

use serde_json::Value;

use crate::context::Context;
use crate::error::Result;

pub(crate) use self::now::now;
pub(crate) use self::uuidv4::uuidv4;

mod now;
mod uuidv4;

/// Evaluation engine function signature
///
/// You can register custom function with the [`function`] method.
///
/// # Arguments
///
/// * `args` - A function arguments
/// * `context` - An evaluation context
///
/// # Examples
///
/// `random()`:
///
/// * `random` - function name
/// * `args` - empty map
///
/// `random(max=1024)`
///
/// * `random` - function name
/// * `args` - map contains `max` key with the `Value::Number(1024)` value
///
/// Visit [`function`] method documentation to see how to register custom function
/// and how it should look like.
///
/// [`Engine`]: struct.Engine.html
/// [`function`]: struct.EngineBuilder.html#method.function
pub type FunctionFn = fn(args: &HashMap<String, Value>, context: &mut Context) -> Result<Value>;