From 327fc39e90c7bfe0115c761d69891dc5fa3e14f9 Mon Sep 17 00:00:00 2001 From: Fuyang Liu Date: Wed, 10 Jul 2019 16:07:47 +0200 Subject: [PATCH 1/2] update the example hello --- examples/hello.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/examples/hello.rs b/examples/hello.rs index 3ab9348af0..d11ba568d4 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -5,19 +5,21 @@ extern crate pretty_env_logger; use hyper::{Body, Request, Response, Server}; use hyper::service::{make_service_fn, service_fn}; -use hyper::rt; async fn hello(_: Request) -> Result, hyper::Error> { Ok(Response::new(Body::from("Hello World!"))) } -async fn serve() { +#[tokio::main] +pub async fn main() { + pretty_env_logger::init(); + let addr = ([127, 0, 0, 1], 3000).into(); let server = Server::bind(&addr) .serve(make_service_fn(|_| { // This is the `Service` that will handle the connection. - // `service_fn_ok` is a helper to convert a function that + // `service_fn` is a helper to convert a function that // returns a Response into a `Service`. async { Ok::<_, hyper::Error>(service_fn(hello)) @@ -30,9 +32,3 @@ async fn serve() { eprintln!("server error: {}", e); } } - -fn main() { - pretty_env_logger::init(); - - rt::run(serve()); -} From 257b7d914e8f6b60f3998bf5d8105f90353a1f2d Mon Sep 17 00:00:00 2001 From: Fuyang Liu Date: Wed, 10 Jul 2019 17:36:24 +0200 Subject: [PATCH 2/2] address PR input --- examples/hello.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/hello.rs b/examples/hello.rs index d11ba568d4..d961797158 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -11,7 +11,7 @@ async fn hello(_: Request) -> Result, hyper::Error> { } #[tokio::main] -pub async fn main() { +pub async fn main() -> Result<(), Box> { pretty_env_logger::init(); let addr = ([127, 0, 0, 1], 3000).into(); @@ -28,7 +28,7 @@ pub async fn main() { println!("Listening on http://{}", addr); - if let Err(e) = server.await { - eprintln!("server error: {}", e); - } + server.await?; + + Ok(()) }