Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify use of #[tokio::main] #743

Closed
hwchen opened this issue Dec 17, 2019 · 4 comments · Fixed by #745
Closed

Clarify use of #[tokio::main] #743

hwchen opened this issue Dec 17, 2019 · 4 comments · Fixed by #745

Comments

@hwchen
Copy link

hwchen commented Dec 17, 2019

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"] }

@anthonyjchriste
Copy link

anthonyjchriste commented Dec 17, 2019

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.

@hwchen
Copy link
Author

hwchen commented Dec 17, 2019

@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.

@seanmonstar
Copy link
Owner

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

@anthonyjchriste
Copy link

@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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants