Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(handler): streamline command definition parsing for improved eff…
…iciency
  • Loading branch information
Tunglies committed Dec 1, 2025
commit 25bacebb14149a70f4a14c80c469e5ebda369f34
36 changes: 17 additions & 19 deletions crates/tauri-macros/src/command/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,23 @@ impl From<Handler> for proc_macro::TokenStream {
) -> Self {
let cmd = format_ident!("__tauri_cmd__");
let invoke = format_ident!("__tauri_invoke__");
let (paths, attrs): (Vec<Path>, Vec<Vec<Attribute>>) = command_defs
.into_iter()
.map(|def| (def.path, def.attrs))
.unzip();
// Build the module-qualified paths for the command name constants emitted by the wrapper macro.
let command_name_consts: Vec<Path> = paths
.iter()
.zip(commands.iter())
.map(|(p, name)| {
let mut p = p.clone();
let last = p
.segments
.last_mut()
.expect("path has at least one segment");
let upper = name.to_string().to_uppercase();
last.ident = format_ident!("__TAURI_COMMAND_NAME_{}", upper);
p
})
.collect();
let (paths, attrs, command_name_consts): (Vec<Path>, Vec<Vec<Attribute>>, Vec<Path>) =
command_defs
.into_iter()
.zip(commands.into_iter())
.map(|(def, command)| {
let path = def.path;
let attrs = def.attrs;
let mut const_path = path.clone();
let last = const_path
.segments
.last_mut()
.expect("path has at least one segment");
let upper = command.to_string().to_uppercase();
last.ident = format_ident!("__TAURI_COMMAND_NAME_{}", upper);
(path, attrs, const_path)
})
.collect();

quote::quote!(move |#invoke| {
let #cmd = #invoke.message.command();
Expand Down