Closed porky11 closed 7 years ago
There are a few ways of creating a Ketos Value
that wraps a Rust function, depending on the type of function you have:
Value::new_foreign_fn
wraps a Rust function with the signature fn(&Context, &mut [Value]) -> Result<Value, Error>
, the way built-in functions (+
, -
, etc.) are implemented.ketos_fn!
wraps any Rust function, so long as its arguments implement FromValueRef
and its return type is Result<T, Error>
where T: Into<Value>
.Value
of the Function
variant, which is like the first option, but avoids a dynamic dispatch call through the ForeignValue
trait. This is done transparently when you use a ModuleBuilder
to add functions to a new module.Cool, so even multiple dispatch is supported. I wouldn't have expected functions in the value module
(isn't there already? I didn't find it) This would make it easier to call rust functions, which is especially useful, when they do things, which cannot be done in ketos