Skip to content

Commit 3fd53d3

Browse files
committed
adjusted fields to match snake case
1 parent a9ace31 commit 3fd53d3

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ fn main() {
253253
```
254254

255255
## Known Issues:
256-
- arguments used in `tauri::command` beginning with `_` aren't supported yet
257-
- due to [tauri internally converting the argument name](https://tauri.app/v1/guides/features/command#passing-arguments),
258-
which results in losing the _ at the beginning
259256
- feature: leptos
260257
- sometimes a closure is accessed after being dropped
261258
- that is probably a race condition where the unlisten function doesn't detach the callback fast enough

tauri-interop-macro/src/command/wrapper.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,16 @@ pub fn prepare(function: ItemFn) -> InvokeCommand {
127127
false
128128
};
129129

130-
match typed.pat.as_ref() {
131-
Pat::Ident(ident) => Some(FieldArg {
132-
ident: ident.ident.clone(),
133-
argument: fn_arg,
134-
requires_lifetime: req_lf,
135-
}),
130+
match typed.pat.as_mut() {
131+
Pat::Ident(ident) => {
132+
// converting the ident to snake case, so it matches the expected snake case
133+
ident.ident = format_ident!("{}", ident.ident.to_string().to_case(Case::Snake));
134+
Some(FieldArg {
135+
ident: ident.ident.clone(),
136+
argument: fn_arg,
137+
requires_lifetime: req_lf,
138+
})
139+
},
136140
_ => None,
137141
}
138142
})

test-project/api/src/cmd.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ tauri_interop::host_usage! {
1010
#[tauri_interop::command]
1111
pub fn empty_invoke() {}
1212

13+
#[tauri_interop::command]
14+
pub fn underscore_invoke(_invoke: u8) {}
15+
1316
#[tauri_interop::command]
1417
pub async fn await_heavy_computing() {
1518
std::thread::sleep(std::time::Duration::from_millis(5000))

test-project/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn main() {
1111
console_error_panic_hook::set_once();
1212

1313
api::cmd::empty_invoke();
14+
api::cmd::underscore_invoke(69);
1415

1516
wasm_bindgen_futures::spawn_local(async {
1617
log::info!("{}", api::cmd::greet("frontend").await);

0 commit comments

Comments
 (0)