[英]Rust mismatched types expected (), found struct `Enumerate
I am trying to return data from coremidi which is a list of midi device names.我正在尝试从 coremidi 返回数据,这是一个 midi 设备名称列表。 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.
我不确定它的格式是什么。如果无法做到这一点,我将尝试在 for 循环中返回每个名称。
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).虽然看起来 tauri 命令可以返回数据,但它们给出的所有示例都对其返回类型进行了注释(即
#[tauri::command]
属性似乎没有重写它)。
So make sure you give your function a return type:所以确保你给你的 function 一个返回类型:
#[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.确切的返回类型可能有所不同,这仅用于说明目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.