I’m trying to create a Tauri app by moving some commands into lib.rs.
lib.rs
#[tauri::command]
pub async fn get_file_path_in_rust(file_path: String) {
println!("The Path Received: {}", file_path);
}
main.rs
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri_plugin_opener::OpenerExt;
use whoami;
use crate::get_file_path_in_rust;
#[tauri::command]
fn get_user() -> String {
whoami::username()
}
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![
get_user,
get_file_path_in_rust
])
.run(tauri::generate_context!())
.expect("error while running tauri app");
}
But when I run it, I get this error:
the name `__cmd__get_file_path_in_rust` is defined multiple times
`__cmd__get_file_path_in_rust` must be defined only once in the macro namespace of this module
I only have the function once, so I don’t understand why the macro is being generated twice.
Question:
What’s the correct way to put #[tauri::command] functions in lib.rs and call them from main.rs?
How do I avoid this duplicate macro error?
get_file_path_in_rustpub(crate)or module-private and see if that fixes it?lib.rs? It only makes sense if you have multiple binaries that need to use it, either as multiple binaries in your crate (but in that case you probably wouldn't have amain.rs) or from other crates (is that the case?)