-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfunc.rs
41 lines (38 loc) · 870 Bytes
/
func.rs
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
41
//! FUnctions
use serde_json::Value;
use crate::error::Error;
/// A (potentially user-defined) function
///
/// The simplest function definition looks like:
///
/// ```jsonc
/// {
/// "def": [ // function definition operator
/// "is_even", // function name
/// [a], // function params
/// // function expression
/// {
/// "===": [
/// {"%": [{"param": "a"}, 2]},
/// 0
/// ]
/// }
/// ]
/// }
/// ```
///
/// Once defined, the above function can be used like:
///
/// ```jsonc
/// {"is_even": [5]} // false
/// {"is_even": [2]} // true
/// ```
///
/// Function expressions may use any of the standard operators or any
/// previously defined functions.
///
pub struct Function {
name: String,
params: Vec<String>,
expression: Value,
}