std_macro_extensions/execute/macro.rs
1/// Execute a synchronous function with given arguments.
2///
3/// # Parameters
4/// - `$path`: The function path.
5/// - `$array`: The primary argument.
6/// - `$arg`...: Optional trailing arguments.
7///
8/// # Returns
9/// - The result of the function call.
10#[macro_export]
11macro_rules! execute {
12 ($path: path, $array: expr) => {
13 $path($array)
14 };
15 ($path: path, $array: expr, $($arg: expr), *) => {
16 $path($array, $($arg), *)
17 };
18}
19
20/// Execute an asynchronous function and return a future.
21///
22/// # Parameters
23/// - `$path`: The async function path.
24/// - `$array`: The primary argument.
25/// - `$arg`...: Optional trailing arguments.
26///
27/// # Returns
28/// - A future that must be `.await`ed.
29#[macro_export]
30macro_rules! execute_async {
31 ($path: path, $array: expr) => {
32 async {
33 $path($array).await
34 }
35 };
36 ($path: path, $array: expr, $($arg: expr),*) => {
37 async {
38 $path($array, $($arg),*).await
39 }
40 };
41}