trg_new_trigger_func

Macro trg_new_trigger_func 

Source
macro_rules! trg_new_trigger_func {
    ($func_name:ident, $arg_name:ident, $body:block) => { ... };
}
Expand description

This macro generates a function that takes a reference to a Box<dyn Any> as an argument and returns a bool. The function body ($body) determines whether the condition is met.

§Usage

Use for defining functions required to create a Trigger object.

§Parameters

  • func_name: An identifier (ident) representing the generated function name.
  • arg_name: An identifier (ident) representing the function argument name.
  • body: A block (block) containing the function implementation.

§Example

// Define a trigger function that print the argument than evaluate whether
// the argument is 5
trg_new_trigger_func!(func_name, arg, {
    let number = trg::cast_arg::<u32>(arg)?;
    println!("{}", number);
    *number == 5
});