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
use std::fmt;
use serde_json::Value;
use error::Error;
pub struct Function {
pub max_args: Option<usize>,
pub min_args: Option<usize>,
pub compiled: Box<Fn(Vec<Value>) -> Result<Value, Error> + Sync + Send>,
}
impl Function {
pub fn new<F>(closure: F) -> Function
where F: 'static + Fn(Vec<Value>) -> Result<Value, Error> + Sync + Send
{
Function {
max_args: None,
min_args: None,
compiled: Box::new(closure),
}
}
}
impl fmt::Debug for Function {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f,
"Function {{ max_args: {:?}, min_args: {:?} }}",
self.max_args,
self.min_args)
}
}