0

I am translating code to version 1.0.1 of Tokio and version 0.10.10 of reqwest. This code does not work:

// 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&paras=1").await.unwrap();
    let text = response.text().await.unwrap();
    println!("{}", text);
}

The program fails at runtime with this message:

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:

The code is basically same as reqwest's simple example - but that was written for an older Tokio version.

I shared the code on the Rust playground but it doesn't even compile there.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Petr Kozelka
  • 7,670
  • 2
  • 29
  • 44
  • It seems like, for some weird reason, [anything that even mentions reqwest will fail to compile](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b95422409fee2cc898320e7598506301) (possibly due to a timeout?). – Aplet123 Dec 29 '20 at 16:34
  • @Aplet123 it might be a limitation of the playground itself, as there is no way (known to me) to specify dependencies – Petr Kozelka Dec 29 '20 at 16:42
  • @Aplet123 linking reqwest exceeds the memory limitations of the playground. – Shepmaster Dec 29 '20 at 16:42
  • 2
    TL;DR the duplicates: reqwest 0.10.10 depends on Tokio 0.2, not Tokio 1.0. Use a matching version of Tokio until the next version of reqwest is released. – Shepmaster Dec 29 '20 at 16:47
  • @Shepmaster I don't see how is that a duplicate, IOW, what was my chance to see answer in THAT before asking THIS. In any case, thanks for the explanation. – Petr Kozelka Dec 29 '20 at 16:54
  • 2
    *how is that a duplicate* — on Stack Overflow, duplicate means "this question is answered by the answers of the other question". Duplicates are **not a bad thing**. *what was my chance to see answer in THAT before asking THIS* — I don't know, it depends on what you searched for, exactly. The point of duplicates is that now people that search for the text in **this** question will be redirected to the answer of **that** question. – Shepmaster Dec 29 '20 at 16:56

0 Answers0