Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Deeply Rename Properties before/after invoke #2732

Open
bradleat opened this issue Aug 23, 2024 · 1 comment
Open

[feat] Deeply Rename Properties before/after invoke #2732

bradleat opened this issue Aug 23, 2024 · 1 comment

Comments

@bradleat
Copy link

bradleat commented Aug 23, 2024

Describe the problem

I have to manually rename objects properties from camelCase to snake_case to pass them to tauri invoke (also on the way back).

For instance, if I have rust code like this:

struct Example {
   pub one_thing: f64;
}

#[tauri::command]
fn echo_example(example_thing: Example) => Result<Example, String> {
   OK(example_thing)
}

Then in javascript I have to do this:


response = await invoke('echo_example`, {
   exampleThing: {
      one_thing: 10.5
   }
})

// format response again

formattedResponse = {
  oneThing: response.one_thing
}

You can imagine this is annnoying for deeply nested structs, objects, esp involving arrays/vecs

Describe the solution you'd like

I'd like to have the case conversion deeply applied.

Alternatives considered

https://serde.rs/attr-rename.html

Additional context

Perhaps the Usage of Serde should be suggested in the documentation.
No response

@bradleat bradleat changed the title [feat] [feat] Deeply Rename Properties before/after invoke Aug 23, 2024
@amrbashir
Copy link
Member

amrbashir commented Sep 24, 2024

Just add #[serde(rename_all = "camelCase")] on your struct

I believe this is more of a documentation issue, so I will just move to tauri-docs

@amrbashir amrbashir transferred this issue from tauri-apps/tauri Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🪵 Backlog
Development

No branches or pull requests

2 participants