Hello, Iam not sure why I am getting this compiler diagnostic error coming up in VSC (my code is below):
error[E0308]: mismatched types
--> src/main.rs:44:8
|
33 | async fn select_http_response<ElementRef>(url: &str, xpath: &str) -> Result<Vec<ElementRef>> {
| ---------- expected this type parameter
...
44 | Ok(selection)
| -- ^^^^^^^^^ expected `Vec<ElementRef>`, found `Vec<ElementRef<'_>>`
| |
| arguments to this enum variant are incorrect
|
= note: expected struct `Vec<ElementRef>`
found struct `Vec<ElementRef<'_>>`
help: the type constructed contains `Vec<ElementRef<'_>>` due to the type of the argument passed
--> src/main.rs:44:5
|
44 | Ok(selection)
| ^^^---------^
| |
| this argument influences the type of `Ok`
async fn select_http_response<ElementRef>(url: &str, xpath: &str) -> Result<Vec<ElementRef>> {
let response = reqwest::get(url).await?;
assert!(response.status().is_success());
let body = response.text().await?;
// parses string of HTML as a document
let fragment = Html::parse_document(&body);
// parses based on a CSS selector
let elements = Selector::parse(xpath);
let selection = fragment.clone().select(&elements.unwrap()).collect::<Vec<_>>();
Ok(selection)
}
#[tokio::main]
async fn main() -> Result<()> {
let url: String = WWW_IMFDB_ORG.to_string() + "/wiki/Category:Rifle";
let xpath: String = ".gallerytext > p > a".to_string();
let guns: Vec<ElementRef> = select_http_response(&url, &xpath).await?;
}