Hi all,
I am new to Rust and I wanted to build a MacOS app to learn the language better.
I decided to use Tauri + Yew to fully emerge on the Rust ecosystem.
My knowledge on web development is quite limited as well.
As a first step, I wanted to introduce a new type that could be shared between the frontend and the backend, thus, I introduced the following struct:
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Person<'a> {
pub name: &'a str,
pub age: u8,
}
Then, I introduced a simple command that expects the type as argument:
#[tauri::command]
fn greet_type(person: Person, storage : State<utils::Storage>) -> String {
println!("Message from rust greet_str{} {}", person.name, person.age);
format!("Hello, You've been greeted from Rust!")
}
and I generated a handler for the command:
invoke_handler(tauri::generate_handler![greet, greet_expanded, greet_type])
Finally, I extended the frontend to invoke the command using the following way:
let args = to_value(&Person { name :"Kappa" , age : 0 }).unwrap();
let new_msg = invoke("greet_type", args).await.as_string().unwrap();
However, I see the following error:
"panicked at 'unexpected exception: JsValue("invalid args person
for command greet_type
: command greet_type missing required key person")'
The error is unclear to me, since the greet_type command does expect a Person as an argument.
As a next experiment, I introduced the following command:
#[tauri::command]
fn greet_expanded(name : &str, age : u8, storage : State<utils::Storage>) -> String {
println!("Message from greet_expanded: Hello, {}!", "Kappa");
format!("Hello, {}! You've been greeted from Rust!", "Kappa")
}
And to my surprise this works..
Could somebody explain this behaviour and how to approach such issues in general?
References I could check/read are also highly appreciated.
Thanks in advance for your help!