Trait quad_compat_rhai::FuncArgs [−][src]
Expand description
Trait that parses arguments to a function call.
Any data type can implement this trait in order to pass arguments to a function call.
Required methods
Parse function call arguments into a container.
Example
use quad_compat_rhai::{Engine, Dynamic, FuncArgs, Scope};
// A struct containing function arguments
struct Options {
pub foo: bool,
pub bar: String,
pub baz: i64,
}
impl FuncArgs for Options {
fn parse<CONTAINER: Extend<Dynamic>>(self, container: &mut CONTAINER) {
container.extend(std::iter::once(self.foo.into()));
container.extend(std::iter::once(self.bar.into()));
container.extend(std::iter::once(self.baz.into()));
}
}
let options = Options { foo: false, bar: "world".to_string(), baz: 42 };
let engine = Engine::new();
let mut scope = Scope::new();
let ast = engine.compile(
"
fn hello(x, y, z) {
if x { `hello ${y}` } else { y + z }
}
")?;
let result: String = engine.call_fn(&mut scope, &ast, "hello", options)?;
assert_eq!(result, "world42");