Trait FuncArgs
pub trait FuncArgs {
// Required method
fn parse<ARGS>(self, args: &mut ARGS)
where ARGS: Extend<Dynamic>;
}
Expand description
Trait that parses arguments to a function call.
Any data type can implement this trait in order to pass arguments to
[Engine::call_fn
][crate::Engine::call_fn].
Required Methods§
fn parse<ARGS>(self, args: &mut ARGS)
fn parse<ARGS>(self, args: &mut ARGS)
Parse function call arguments into a container.
§Example
use 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<ARGS: Extend<Dynamic>>(self, args: &mut ARGS) {
args.extend(Some(self.foo.into()));
args.extend(Some(self.bar.into()));
args.extend(Some(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");
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.