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

The example doesn't work with latest version 0.14.12 #68

Open
chiro-hiro opened this issue Aug 28, 2021 · 3 comments
Open

The example doesn't work with latest version 0.14.12 #68

chiro-hiro opened this issue Aug 28, 2021 · 3 comments

Comments

@chiro-hiro
Copy link

The given code on your home page:

use std::{convert::Infallible, net::SocketAddr};
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};

async fn handle(_: Request<Body>) -> Result<Response<Body>, Infallible> {
    Ok(Response::new("Hello, World!".into()))
}

#[tokio::main]
async fn main() {
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

    let make_svc = make_service_fn(|_conn| async {
        Ok::<_, Infallible>(service_fn(handle))
    });

    let server = Server::bind(&addr).serve(make_svc);

    if let Err(e) = server.await {
        eprintln!("server error: {}", e);
    }
}

The result:

   Compiling http-server v0.1.0 (/Users/chiro/GitHub/rust-playground/http-server)
error[E0432]: unresolved import `hyper::Server`
 --> src/main.rs:2:38
  |
2 | use hyper::{Body, Request, Response, Server};
  |                                      ^^^^^^ no `Server` in the root

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: could not compile `http-server`

To learn more, run the command again with --verbose.
@IsaacCloos
Copy link
Contributor

Hi @chiro-hiro 👋🏻,

I think you raise a great point. It would be helpful to annotate in some way which features are required to make these examples run.

Also, since there are multiple 'primary versions' (if you will), it would be nice to see which version of Hyper (1.0 or otherwise) is being referenced in the code snippets outside the version-specific guide pages.

What do you think?

cc @oddgrd (I'd be happy to attempt whatever this issue manifests into 👍🏻)

@oddgrd
Copy link
Contributor

oddgrd commented May 10, 2023

Hey Isaac! I think we have the imports covered in the guides, but they are missing for the example on the homepage. I suppose the reason they are not there on the homepage is to keep it brief. It would be nice to make it clear that the homepage code is 1.0, as you suggested. Perhaps we should link to the https://hyper.rs/guides/1/server/hello-world/ guide, since it's pretty much the same as the homepage but including imports?

@annmuor
Copy link

annmuor commented Oct 3, 2023

Good evening.

I was wondering if this issue is already created and yes, it is :)
Most server examples is not working in latest hyper.

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

No branches or pull requests

4 participants