Reputation: 127
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())
}
Upvotes: 1
Views: 650
Reputation: 10196
While it looks like tauri commands can return data, all the examples they give have their return type annotated (i.e. 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.
Upvotes: 1