Skip to content

Commit d36b726

Browse files
authored
fix(macros): collision when command is named cmd (#1802)
1 parent 1ab8dd9 commit d36b726

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎.changes/fix-command-named-cmd.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-macros": patch
3+
---
4+
5+
Fixes a name collision when the command function is named `cmd`.

‎core/tauri-macros/src/command/handler.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl From<Handler> for proc_macro::TokenStream {
5252
}: Handler,
5353
) -> Self {
5454
quote::quote!(move |invoke| {
55-
let cmd = invoke.message.command();
56-
match cmd {
55+
let __tauri_cmd__ = invoke.message.command();
56+
match __tauri_cmd__ {
5757
#(stringify!(#commands) => #wrappers!(#paths, invoke),)*
5858
_ => {
59-
invoke.resolver.reject(format!("command {} not found", cmd))
59+
invoke.resolver.reject(format!("command {} not found", __tauri_cmd__))
6060
},
6161
}
6262
})

‎examples/commands/src-tauri/src/commands.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use tauri::{command, State};
66

7+
#[command]
8+
pub fn cmd(_argument: String) {}
9+
710
#[command]
811
pub fn simple_command(argument: String) {
912
println!("{}", argument);

‎examples/commands/src-tauri/src/main.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// we move some basic commands to a separate module just to show it works
1111
mod commands;
12+
use commands::cmd;
1213

1314
use serde::Deserialize;
1415
use tauri::{command, Params, State, Window};
@@ -167,6 +168,7 @@ fn main() {
167168
force_async_with_result,
168169
commands::simple_command,
169170
commands::stateful_command,
171+
cmd,
170172
async_simple_command,
171173
future_simple_command,
172174
async_stateful_command,

0 commit comments

Comments
 (0)