Windows10環境下です。
Rustのソースをビルドした時、以下のエラーが発生しました。
error[E0308]: mismatched types
--> src\main.rs:25:43
|
25 | let a:Result<Channel, Box<dyn Error>> = example_feed();
| ------------------------------- ^^^^^^^^^^^^^^ expected enum `Result`, found opaque type
| |
| expected due to this
|
note: while checking the return type of the `async fn`
--> src\main.rs:14:28
|
14 | async fn example_feed() -> Result<Channel, Box<dyn Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, found opaque type
= note: expected enum `Result<Channel, Box<dyn std::error::Error>>`
found opaque type `impl Future<Output = Result<Channel, Box<(dyn std::error::Error + 'static)>>>`
For more information about this error, try `rustc --explain E0308`.
ソースは以下です。
async fn example_feed() -> Result<Channel, Box<dyn Error>> {
let content = reqwest::get("https://www.reddit.com/r/programming/.rss")
.await?
.bytes()
.await?;
let channel = Channel::read_from(&content[..])?;
Ok(channel)
}
#[tauri::command]
fn get_rss(_state: tauri::State<StateValue>) -> String {
let a:Result<Channel, Box<dyn Error>> = example_feed();
match a{
Ok(result)=> println!("{:?}",result),
Err(msg)=>println!("No"),
}
String::from("test")
}
掲題の通り、具体的に何をどう修正したら良いのか、わかりません。
私は何をしたら良いのでしょうか?
*追記
awaitを使用したところ、次から次へとコンパイラから指示が飛び、
最終的に以下のソースとエラーとなりました。
error[E0597]: `__tauri_message__` does not live long enough
--> src\main.rs:23:1
|
23 | #[tauri::command]
| ^^^^^^^^^^^^^^^^-
| | |
| | `__tauri_message__` dropped here while still borrowed
| borrowed value does not live long enough
| argument requires that `__tauri_message__` is borrowed for `'static`
...
37 | .invoke_handler(tauri::generate_handler![get_rss])
| --------------------------------- in this macro invocation
|
= note: this error originates in the macro `__cmd__get_rss` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0597`.
warning: `app` (bin "app") generated 1 warning
error: could not compile `app` due to previous error; 1 warning emitted
ソース
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::error::Error;
use rss::Channel;
struct StateValue(i32);
async fn example_feed() -> Result<Channel, Box<dyn Error>> {
let content = reqwest::get("https://www.reddit.com/r/programming/.rss")
.await?
.bytes()
.await?;
let channel = Channel::read_from(&content[..])?;
Ok(channel)
}
#[tauri::command]
async fn get_rss(_state: tauri::State<'_,StateValue>) -> String {
let a:Result<Channel, Box<dyn Error>> = example_feed().await;
match a{
Ok(result)=> println!("{:?}",result),
Err(msg)=>println!("No"),
}
String::from("test")
}
fn main() {
tauri::Builder::default()
.manage(StateValue(0))
.invoke_handler(tauri::generate_handler![get_rss])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
何をどうしたら良いのか、さっぱりわかりません……