#Tauri IPC how it's work ?

6 messages · Page 1 of 1 (latest)

hollow pewter
#

Hi,

I try to use : https://v2.tauri.app/develop/calling-rust/#returning-array-buffers to return some data in frontend.
So i code a very simple example :

#[tauri::command]
pub async fn sql_request(code_sql: &str, sources:Vec<source::Source>) -> Response {
    let bytes: [u8; 3] = [1, 0, 2];
    tauri::ipc::Response::new(bytes)
} 

And i have this error and i not sure how to solve it (i kind a newbie in rust) :

error[E0277]: async commands that contain references as inputs must return a `Result`
  --> src/commands.rs:20:74
   |
20 | pub async fn sql_request(code_sql: &str, sources:Vec<source::Source>) -> Response {
   |                                                                          ^^^^^^^^ the trait `AsyncCommandMustReturnResult` is not implemented for `tauri::ipc::Response`
   |
   = help: the trait `AsyncCommandMustReturnResult` is implemented for `Result<A, B>`
   = note: required for the cast from `&tauri::ipc::Response` to `&dyn AsyncCommandMustReturnResult`

error[E0277]: the trait bound `InvokeResponseBody: std::convert::From<[u8; 3]>` is not satisfied
   --> src/commands.rs:22:31
    |
22  |     tauri::ipc::Response::new(bytes)
    |     ------------------------- ^^^^^ the trait `std::convert::From<[u8; 3]>` is not implemented for `InvokeResponseBody`, which is required by `[u8; 3]: Into<InvokeResponseBody>`

Laurent.

Tauri

The cross-platform app building toolkit

grand acorn
hollow pewter
#

Thank's for your answer.
I try but i still have an error :

#
use tauri::ipc::Response;
use crate::entities::source;

use serde::{Serialize, Deserialize};

#[derive(Debug, thiserror::Error, Deserialize, Serialize)]
enum Error {
    #[error("invalid name: {0}")]
    InvalidName(String),
}

#[derive(Deserialize, Serialize)]
pub struct MyReponse {
    pub text:String
}

#[tauri::command]
pub async fn sql_request(code_sql: &str, sources:Vec<source::Source>) -> Result<MyReponse,Error> {
    let test:MyReponse= MyReponse {text:String::from("someText")};
    Ok(tauri::ipc::Response::new(test))
} 
#

Ok(tauri::ipc::Response::new(test))
| ------------------------- ^^^^ the trait From<MyReponse> is not implemented for InvokeResponseBody, which is required by MyReponse: Into<InvokeResponseBody>
| |
| required by a bound introduced by this call