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 whichCallback
binding function to use. However, if you declare a closure as a variable and then try to pass it to thecallback
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);
§If you have closure variable with more or less than 1 argument, you can use on the the following direct methods:
§A closure supplied directly to the
callback
macro can accept 0-8 arguments:let callback = callback!(|value:bool|{ // });
Output will be as follows:
let callback = Callback::new_with_args_1(|value:bool|{ // });
§Example of a closure with 2 arguments:
let callback = callback!(|arg1:u16, value:bool|{ // });
Output will be as follows:
let callback = Callback::new_with_args_2(|arg1:u16, value:bool|{ // });