use futures::executor::block_on;
async fn request() -> Result<(), reqwest::Error> {
let response = reqwest::get("https://rustcc.cn").await?; // Panic here according to backtrace
Ok(())
}
fn main() -> Result<(), reqwest::Error> {
block_on(request())
}
You didn't set up an async runtime.
You can do it like so:
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
request().await?;
Ok(())
}
this works after adding tokio with cargo add tokio --features=full
Alternatively, you can also create the runtime explicitly:
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(request())?;
Ok(())
}
1 Like
Yeah, reqwest
requires the tokio runtime. It won't work with futures::executor
.
Thanks.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.