简体   繁体   中英

Tauri Rust Invoke and return to frontend issues

I have invoked a function from my frontend to my backend. It works however I want to return results back to frontend and all I get is null

#[tauri::command]
fn get_midi_device_list() {
    // "Hello from Rust!".into()
    println!("System destinations:");

    for (i, destination) in coremidi::Destinations.into_iter().enumerate() {
        let display_name = get_display_name(&destination);
        println!("[{}] {}", i, display_name);

    }
}

the tauri github page has many examples of commands with results. maybe one of them will work for you.

for instance:

#[command]
fn simple_command_with_result(argument: String) -> Result<String, MyError> {
  println!("{}", argument);
  (!argument.is_empty())
    .then(|| argument)
    .ok_or(MyError::FooError)
}

Your function does not return anything (other than () ). So maybe try to actually return a value?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM