Reqwest: Clarify use of `#[tokio::main]`

Created on 17 Dec 2019  路  4Comments  路  Source: seanmonstar/reqwest

This is also an issue in hyperium/hyper#2028.

Basically, the #[tokio::main] macro is used for examples but the dependency is not explicitly mentioned in readme or docs. Could be pretty confusing. I haven't seen an issue with reqwest yet, so this is preemptive, but I've seen people have issues with hyper and warp.

Also, the dep should look something like:

tokio = { version = "0.2.3", features = ["macros"] }

Most helpful comment

I've opened #745 to add a note to the examples.

All 4 comments

Yes, I'm running into a similar issue trying to follow the github examples. Essentially I'm getting

--> src/main.rs:4:3 | 4 | #[tokio::main] | ^^^^^ use of undeclared type or moduletokio

But I can't find any documentation about how to properly use this anywhere.

I was able to eventually get it to work by adding tokio = "0.2.0-alpha.6" to my Cargo.toml, but I had to try a bunch of different versions until I could find one that worked.

I feel that this should be listed in the Requirements section on the README.md file if it's going to be included in all the examples.

@anthonyjchriste note that when using the non-alpha version of tokio, you'll have to use the feature "macros", see original comment.

The need to specify features is because of an architectural change to the whole tokio crate, I can explain more or provide a look if needed, but I'm on phone at the moment.

I've opened #745 to add a note to the examples.

@hwchen Thank you! That is very useful information. I'm fairly new to async/await and am finding the ecosystem a bit daunting. I'm writing a web scraper as a pet project and figured that would be a great chance to get into the async/await ecosystem.

What you explained makes perfect sense and I was able to find more information in Tokio's blog post: https://tokio.rs/blog/2019-11-tokio-0-2/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yazaddaruvala picture yazaddaruvala  路  5Comments

amesgen picture amesgen  路  6Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  路  6Comments

silvioprog picture silvioprog  路  5Comments

AmarOk1412 picture AmarOk1412  路  5Comments