Open ben0x539 opened 3 years ago
We've had similar insights into other recipes. We've tried to avoid that two ways: 1 there's a cargo.toml file in the cookbook https://github.com/rust-lang-nursery/rust-cookbook/blob/master/Cargo.toml but it isn't very discoverable. 2. We put badges on the recipies to help people know which crates to import. This recipe was originally authored for synchronous reqwest. when it was updated, the tokio badge wasn't added. I think adding the tokio badge to the updated recipes would be a good solution.
I just ran into this. @AndyGauge you're right — I wished I had a Cargo.toml
file to go with the code, because I tried many combinations of specifying the dependencies, and couldn't get it working.
If the only thing keeping this from working is correct toml
configuration, could we add a link to it from a page header or footer? To me, the code is incomplete without it.
@AndyGauge Ok, that doesn't work: naively using https://github.com/rust-lang-nursery/rust-cookbook/blob/master/Cargo.toml with the sample code at https://rust-lang-nursery.github.io/rust-cookbook/web/clients/requests.html:
error: couldn't read build.rs: No such file or directory (os error 2)
error: aborting due to previous error
error: could not compile `rust-cookbook`
This example also doesn't work via the arrow button to run via the web. I think it's safe to say that many examples in the cookbook are broken. Has there been thinking about automated testing?
A pal just ran into this and was stumped: If you copy the first example from web/clients/api/rest-get.md into a new cargo binary project and add the latest versions of reqwest and tokio to your Cargo.toml so it builds, you panic because #[tokio::main] is coming from a different tokio than what reqwest uses, so the reqwest calls are supposedly not on a tokio runtime.
You can probably figure out what is going on from googling the error message, but I suspect someone browsing a cookbook for examples to play with may not be up for package version debugging. idk if there's a robust way to save people from this terrible fate. :(