pub type RsCelFunction = dyn Fn(CelValue, Vec<CelValue>) -> CelValue;Expand description
Prototype for a function binding.
Rust-accelerated functions can be used to extend
the base languageās functionality. The this argument refers to an object the function
is being run on (i.e. foo.bar()). The args argument refers to any arguments passed
to the function within the parenthesis, in order passed. The return value of a function
should be a single ValueCell wrapped in a ValueCellResult.
An example of a function impl that collects the keys of an object and returns them as a list:
use rscel::*;
fn keys_impl(this: CelValue, args: &[CelValue]) -> CelResult<CelValue> {
if args.len() == 0 {
return Err(CelError::misc("keys() expects 0 arguments"));
}
if let CelValue::Map(map) = this {
Ok(CelValue::from_list(map.keys().map(|x| x.as_str().into()).collect()))
} else {
Err(CelError::misc("keys() only supported for map type"))
}
}