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

Hello example failing to build #400

Open
jcbritobr opened this issue Feb 8, 2020 · 13 comments
Open

Hello example failing to build #400

jcbritobr opened this issue Feb 8, 2020 · 13 comments

Comments

@jcbritobr
Copy link

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

@pksunkara
Copy link
Contributor

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

@jcbritobr
Copy link
Author

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 jcbritobr reopened this Feb 14, 2020
@kahlil29
Copy link

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

@pksunkara
Copy link
Contributor

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

@kahlil29
Copy link

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 😄

@jcbritobr
Copy link
Author

jcbritobr commented Feb 24, 2020 via email

@blueskyjunkie
Copy link

blueskyjunkie commented Apr 13, 2020

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

@kahlil29
Copy link

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

@blueskyjunkie
Copy link

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

@sinistersnare
Copy link

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?

@colinbankier
Copy link
Collaborator

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.

@msrd0
Copy link
Member

msrd0 commented Sep 11, 2020

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?

@nyarly
Copy link
Contributor

nyarly commented Oct 5, 2020

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.

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

No branches or pull requests

8 participants