简体   繁体   中英

Rust mismatched types expected (), found struct `Enumerate

I am trying to return data from coremidi which is a list of midi device names. I am not sure what format its in. If that can't be done I am trying to return each name in the for loop.

I keep getting a mismatched types.

#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

extern crate coremidi;

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![get_midi_device_list])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

#[tauri::command]
fn get_midi_device_list() {
    println!("System destinations:");

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

    println!();
    println!("System sources:");

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

    //Trying to return data from line below or the data in the for  loop
    coremidi::Destinations.into_iter().enumerate()
}

fn get_display_name(endpoint: &coremidi::Endpoint) -> String {
    endpoint
        .display_name()
        .unwrap_or_else(|| "[Unknown Display Name]".to_string())
}

While it looks like tauri commands can return data, all the examples they give have their return type annotated (ie the #[tauri::command] attribute doesn't seem to rewrite that).

So make sure you give your function a return type:

#[tauri::command]
fn get_midi_device_list() -> impl Iterator<(usize, Destination)> {
  // ...

  coremidi::Destinations.into_iter().enumerate()
}

The exact return type may be something different, this is just for illustrative purposes.

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