Hi
I'm trying for the first time to use the async version of reqwest and it's throwing an error I cannot decode.
My async function.
async fn get_page(uri: reqwest::Url) -> Result<String, reqwest::Error> {
let client = reqwest::Client::new();
let text = client
.get(uri)
.header(
reqwest::header::USER_AGENT,
"MemBot (+https://superrune.dk/membot/)",
)
.send()
.await?
.text()
.await?;
Ok(text)
}
And the funtion is the used like this
pub fn get_article(link: &str, id: &uuid::adapter::Hyphenated) -> Option<String> {
....
if let Ok(body) = get_page(uri) {
....
return Some(article);
}
None
}
Gives me this compile time errors
error[E0308]: mismatched types
|
20 | if let Ok(body) = get_page(uri) {
| ^^^^^^^^ expected opaque type, found enum `std::result::Result`
...
151 | async fn get_page(uri: reqwest::Url) -> Result<(), reqwest::Error> {
| -------------------------- the `Output` of this `async fn`'s expected opaque type
|
= note: expected opaque type `impl std::future::Future`
found enum `std::result::Result<_, _>`
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
20 | if let Ok(body) = get_page(uri) {
| ^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `str`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature
Can some one help me figure out this riddle, because I feel prettt incompetent right now.