expressive/src/function/mod.rs
Sebastian Schmidt 92da684c69 Implement min and max builtin functions
Implement #8, partially implement #1
2019-03-19 20:08:23 +02:00

30 lines
686 B
Rust

use error::{self, Error};
use value::Value;
pub mod builtin;
pub struct Function {
argument_amount: Option<usize>,
function: Box<Fn(&[Value]) -> Result<Value, Error>>,
}
impl Function {
pub fn new(
argument_amount: Option<usize>,
function: Box<Fn(&[Value]) -> Result<Value, Error>>,
) -> Self {
Self {
argument_amount,
function,
}
}
pub fn call(&self, arguments: &[Value]) -> Result<Value, Error> {
if let Some(argument_amount) = self.argument_amount {
error::expect_function_argument_amount(arguments.len(), argument_amount)?;
}
(self.function)(arguments)
}
}