Macro workflow_wasm::callback::callback

source ·
callback!() { /* proc-macro */ }
Expand description

creates a Callback instance by inspecting a given closure signature

// include dependencies
use workflow_wasm::prelude::*;

Warning: the callback macro expects to receive a closure as an argument and will use this closure’s signature to determine which Callback binding function to use. However, if you declare a closure as a variable and then try to pass it to the callback macro, the macro will fail with an error as follows: “closure is expected to take 1 argument”

  • §If passing closure as variable, it will accept only 1 argument:
let closure_as_variable = |value:bool|{
    ...
};
let callback = callback!(closure_as_variable);

The above code will create callback like this:

let callback = Callback::new(closure_as_variable);
  • §Examples of incorrect use:
// 2 arguments
let closure_as_variable = |arg1:bool, arg2:u16|{
    //...
};
let callback = callback!(closure_as_variable);
// no arguments
let closure_as_variable = ||{
    //...
};
let callback = callback!(closure_as_variable);