问题描述
我正在将代码翻译成 Tokio 的 1.0.1 版和 reqwest 的 0.10.10 版。此代码不起作用:
// Cargo.toml dependencies:
// reqwest = "0.10.10"
// tokio = { version = "1.0.1",features = ["full"] }
#[tokio::main]
async fn main() {
let response = reqwest::get("https://baconipsum.com/api/?type=meat-and-filler&type=text¶s=1").await.unwrap();
let text = response.text().await.unwrap();
println!("{}",text);
}
程序在运行时失败并显示以下消息:
thread 'main' panicked at 'not currently running on the Tokio runtime.',/home/pk/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.24/src/runtime/handle.rs:118:28
stack backtrace:
代码与 reqwest 的 simple example 基本相同 - 但它是为较旧的 Tokio 版本编写的。
I shared the code on the Rust playground 但它甚至没有在那里编译。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)