tauri
tauri copied to clipboard
Compile error for async stateful commands that don't return a `Result`
Describe the bug
Stateful async commands that don't return a Result give a compiler error.
To Reproduce
Example:
#[command]
pub async fn get_info(app: State<'_, Data>) -> bool {
true
}
There's no error if you remove async, remove the app argument, or change the return type to a Result works.
Platform and Versions
Details
Operating System - Mac OS, version 10.15.7 X64
Node.js environment
Node.js - 14.16.0
@tauri-apps/cli - 1.0.0-beta.10
@tauri-apps/api - 1.0.0-beta.8
Global packages
npm - 6.14.11
yarn - 1.22.10
Rust environment
rustc - 1.54.0
cargo - 1.54.0
App directory structure
/node_modules
/src-tauri
/build
/.git
/src
App
tauri.rs - 1.0.0-beta.8
build-type - bundle
CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
distDir - ../build
devPath - http://localhost:8000
framework - Svelte
Stack Trace
error[E0597]: `__tauri_message__` does not live long enough
--> src/cmd.rs:93:1
|
93 | #[command]
| ^^^^^^^^^-
| | |
| | `__tauri_message__` dropped here while still borrowed
| borrowed value does not live long enough
| argument requires that `__tauri_message__` is borrowed for `'static`
same problem
Is there any interim solution?
For now you just have to return a Result. If you don't want to return anything from the command it can be as simple as Result<(), ()> or in case of the OP's example it'd be Result<bool, ()>.
This doesn't change what you'll receive on the JavaScript side. Ok will resolve the Promise and Err will reject it.