#tauri #front-end #api-bindings

tauri-wasm

The tauri framework library for pure rust frontend

6 releases

Uses new Rust 2024

new 0.2.0 Apr 7, 2025
0.1.4 Apr 5, 2025
0.1.2 Mar 27, 2025

#184 in WebAssembly

Download history 140/week @ 2025-03-12 98/week @ 2025-03-19 130/week @ 2025-03-26 327/week @ 2025-04-02

695 downloads per month

MIT license

26KB
484 lines

tauri-wasm

The tauri framework library for pure rust frontend with wasm-bindgen

About

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.

Getting Started

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.

Dependencies

~0.8–3.5MB
~68K SLoC