我是新手,我正在尝试使用人造丝从一系列 URL 中获取响应
use rayon::prelude::*;
use reqwest::*;
fn main() -> Result<()> {
let urls = vec!["https://example.com"];
urls.par_iter().for_each(|url: &&str| -> Result<()> {
println!("Hello... {:?}", url);
let resp = reqwest::blocking::get(url)?.text()?;
println!("{:#?}", resp);
Ok(())
});
Ok(())
}
但我收到了这个错误
error[E0271]: type mismatch resolving `<[closure@src\main.rs:252:30: 257:6] as FnOnce<(&&str,)>>::Output == ()`
--> src\main.rs:252:21
|
252 | urls.par_iter().for_each(|url| -> Result<()> {
| ^^^^^^^^ expected enum `std::result::Result`, found `()`
|
= note: expected enum `std::result::Result<(), reqwest::Error>`
found unit type `()`
error[E0277]: the trait bound `&&str: IntoUrl` is not satisfied
--> src\main.rs:254:20
|
254 | let resp = reqwest::blocking::get(url)?.text()?;
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoUrl` is not implemented for `&&str`
|
::: mod.rs:106:15
|
106 | pub fn get<T: crate::IntoUrl>(url: T) -> crate::Result<Response> {
| -------------- required by this bound in `reqwest::blocking::get`
|
= help: the following implementations were found:
<&'a str as IntoUrl>