7 unstable releases (3 breaking)

0.4.0 Jan 11, 2021
0.3.0 Aug 14, 2020
0.2.1 Jun 20, 2020
0.1.2 Jun 13, 2020

#53 in #cmd

MIT license

7KB
88 lines

tauri-async-handler

Usage

Cargo.toml:

[dependencies]
tauri-async-handler = "0.1"

src-tauri/main.rs:

mod cmd;

use serde_json::json;
use tauri_async_handler::*;

fn main() {
  tauri::AppBuilder::new()
    .async_handler(None, |cmd: cmd::Cmd| async {
      use cmd::Cmd::*;
      Ok(match cmd {
        MyCustomCommand{ argument } => {
          println!("arg {}", argument);
          let world = "world";
          json!({
            "hello": world
          })
        }
      })
    })
    .build()
    .run();
}

JavaScript:

const myCustomCommand = (argument) => {
  return window.tauri.promisified({
    cmd: 'myCustomCommand',
    argument,
  })
}
myCustomCommand.then((r) => console.log('myCustomCommand', r))

lib.rs:

Usage

Cargo.toml:

[dependencies]
tauri-async-handler = "0.4"

src-tauri/main.rs:

mod cmd;


use serde_json::json;
use tauri_async_handler::*;

fn main() {
  tauri::AppBuilder::new()
    .async_handler(None, |cmd: cmd::Cmd| async {
      use cmd::Cmd::*;
      Ok(match cmd {
        MyCustomCommand{ argument } => {
          println!("arg {}", argument);
          let world = "world";
          json!({
            "hello": world
          })
        }
      })
    })
    .build()
    .run();
}

JavaScript:

const myCustomCommand = (argument) => {
  return window.tauri.promisified({
    cmd: 'myCustomCommand',
    argument,
  })
}
myCustomCommand.then((r) => console.log('myCustomCommand', r))

Dependencies

~26–40MB
~516K SLoC