| Crates.io | tauri-wasm |
| lib.rs | tauri-wasm |
| version | 0.2.0 |
| created_at | 2025-03-16 23:01:16.488783+00 |
| updated_at | 2025-04-07 07:48:51.061142+00 |
| description | The tauri framework library for pure rust frontend |
| homepage | |
| repository | https://github.com/nanoqsh/tauri-wasm |
| max_upload_size | |
| id | 1594840 |
| size | 32,569 |
Interact with a Tauri backend using the pure Rust library. You don't need NPM or any other JavaScript tools to build a frontend, use Cargo instead.
This crate is designed for Tauri version 2.0 and above.
Let's write the frontend part:
use {
gloo::console,
wasm_bindgen::prelude::*,
};
#[wasm_bindgen]
pub async fn start() -> Result<(), JsError> {
// first, check if we are running in a Tauri environment
if !tauri_wasm::is_tauri() {
console::error!("tauri was not detected!");
return;
}
// invoke the "hello" command on the backend
let message = tauri_wasm::invoke("hello").await?;
// log the response from the backend
console::log!("message: ", message);
Ok(())
}
When wasm_bindgen attribute exports our start function to the JS runtime, we can call it from frontend.
On the backend part let's write this:
// define the "hello" command
#[tauri::command]
fn hello() -> String {
println!("frontend invoked hello");
"message from backend".to_owned()
}
// configure the backend
pub fn run() {
tauri::Builder::default()
// register the "hello" command
.invoke_handler(tauri::generate_handler![hello])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
For more details, see the example in the repository.