gotham icon indicating copy to clipboard operation
gotham copied to clipboard

Hello example failing to build

Open jcbritobr opened this issue 4 years ago • 13 comments

The example https://github.com/gotham-rs/gotham/tree/master/examples/hello_world fails to build. Seems there is a wrong module being imported, or api had changes and example wasn't updated

assert_eq!(response.status(), StatusCode::Ok); ^^^^^^^^^^ use of undeclared type or module StatusCode

jcbritobr avatar Feb 08 '20 12:02 jcbritobr

Hey, how are you building it? We had re-exported hyper in gotham.

pksunkara avatar Feb 12 '20 11:02 pksunkara

Hey, how are you building it? We had re-exported hyper in gotham.

Hello. Im just compiling with cargo. 'cargo build'

There is no additional configuration in cargo.toml

jcbritobr avatar Feb 14 '20 14:02 jcbritobr

I got hit by this a couple of times when trying out some examples. I think the problem boils down to the fact that in the Cargo.toml of the examples, the local version of gotham is used a dependency, but I had pointed to the latest version in my Cargo.toml

kahlil29 avatar Feb 19 '20 11:02 kahlil29

Yup, you are not supposed to modify the Cargo.toml from examples. But I think @colinbankier should do a pre-release soon and finalize the roadmap for 5.0 so we can actually push 5.0

pksunkara avatar Feb 19 '20 12:02 pksunkara

I would think that most people (atleast this is what I do, usually) would compile and run example code and then copy paste snippets or the entire thing into a project in which they want to use the code/tool. So imo, there should be either a note or gotcha in the documentation along with something that would guide or help people using the library to use the example code/concept in their code. I'm willing to write this/open a PR for this if someone can help/review/guide me 😄

kahlil29 avatar Feb 24 '20 03:02 kahlil29

If we can't run a simple code snnipet, with simple cargo confuguration, I think we have an issue in documentation.

Em seg, 24 de fev de 2020 00:02, Kahlil Abreu [email protected] escreveu:

I would think that most people (atleast this is what I do, usually) would compile and run example code and then copy paste snippets or the entire thing into a project in which they want to use the code/tool. So imo, there should be either a note or gotcha in the documentation along with something that would guide or help people using the library to use the example code/concept in their code. I'm willing to write this/open a PR for this if someone can help/review/guide me 😄

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/gotham-rs/gotham/issues/400?email_source=notifications&email_token=ABSGNFUCBPTVLRGM63D7JV3REM2C5A5CNFSM4KR2CMYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMWQIVY#issuecomment-590152791, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSGNFT4S5KNC2I2UEI5V6DREM2C5ANCNFSM4KR2CMYA .

jcbritobr avatar Feb 24 '20 09:02 jcbritobr

@kahlil29 Could you post your proposed solution here? So at least in absence of documentation those (like me) searching for a solution to this are somewhat likely to find this issue and be able to use your solution.

I've observed several problems in trying to copy-paste an example into my own project. The example uses something like this in the test:

use gotham::hyper::StatusCode;
assert_eq!(response.status(), StatusCode::OK);

The first problem is that gotham::hyper::StatusCode is not available outside of Gotham.

Since Gotham appears to be re-mapping hyper::StatusCode which itself is re-mapping http::StatusCode I've tried the following

use hyper::StatusCode;
assert_eq!(response.status(), StatusCode::OK);
use http::StatusCode;
assert_eq!(response.status(), StatusCode::OK);

But these both fail to compile with "E0277 can't compare http::status::StatusCode with http::status::StatusCode".

Since StatusCode implements std::cmp::{Eq,PartialEq} it looks like a trait import problem, but trying to import Eq, PartialEq explicitly gives me an "unused import" warning and the comparison error remains.

use http::StatusCode;
use std::cmp::{Eq,PartialEq};
assert_eq!(response.status(), StatusCode::OK);

Any suggestions?

blueskyjunkie avatar Apr 13 '20 15:04 blueskyjunkie

@blueskyjunkie Unfortunately I cannot remember vividly, but could you try adding hyper = "0.12.0" to your Cargo.toml and see if it works? If I remember correctly, after some fiddling around with the versions, it worked.

kahlil29 avatar Apr 14 '20 12:04 kahlil29

@kahlil29 Gotcha. It seems you have to make sure the versions of hyper and http you import into your project are exactly the same as those used by gotham itself.

Presumably there's a Cargo way to do this, but in the Intellij IDEA IDE project I just looked at the "External libraries" drop down tree in the project structure to find which versions of http and hyper are imported automatically by gotham.

image

and then made sure those versions are imported in my Cargo.toml (I'm importing them as test dependencies for now):

image

Definitely a documentation issue at the moment, but also comprises a maintenance issue because you have to manually track the http/hyper versions in your own project. I think the fix is for gotham to publically export it's hyper/http dependencies for transparent use by a dependent project like hyper does for it's http dependencies.

blueskyjunkie avatar Apr 14 '20 13:04 blueskyjunkie

Yes, what is the status of 0.5. There are significant differences between what the examples have and what is needed to make it work with 0.4. When can a 0.5 be expected?

sinistersnare avatar Apr 25 '20 22:04 sinistersnare

Yes, what is the status of 0.5. There are significant differences between what the examples have and what is needed to make it work with 0.4. When can a 0.5 be expected?

@nyarly - are you able to release a gotham 0.5.0-rc.0? Just responding here in case you don't see the chat in gitter about it.

colinbankier avatar Apr 29 '20 03:04 colinbankier

Version 0.5.0 has been released so the issues mentioned above should've been fixed, but examples on the master branch will always track master, so I'm not really sure how you propose this to not happen again in the future @kahlil29?

msrd0 avatar Sep 11 '20 09:09 msrd0

I'd think that the thing to do really is a documentation change - add comments to the examples themselves, or their READMEs or the README in the top level examples directory. Something to the effect that if you're going to C&P, be aware that versions are still very significant, and you'll want to work from the tag matching the version of Gotham that you're using.

As I'm formulating that response, I think there's a overarching issue with a unified docs strategy.

nyarly avatar Oct 05 '20 17:10 nyarly