@@ -5,19 +5,21 @@ extern crate pretty_env_logger;
5
5
6
6
use hyper:: { Body , Request , Response , Server } ;
7
7
use hyper:: service:: { make_service_fn, service_fn} ;
8
- use hyper:: rt;
9
8
10
9
async fn hello ( _: Request < Body > ) -> Result < Response < Body > , hyper:: Error > {
11
10
Ok ( Response :: new ( Body :: from ( "Hello World!" ) ) )
12
11
}
13
12
14
- async fn serve ( ) {
13
+ #[ tokio:: main]
14
+ pub async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
15
+ pretty_env_logger:: init ( ) ;
16
+
15
17
let addr = ( [ 127 , 0 , 0 , 1 ] , 3000 ) . into ( ) ;
16
18
17
19
let server = Server :: bind ( & addr)
18
20
. serve ( make_service_fn ( |_| {
19
21
// This is the `Service` that will handle the connection.
20
- // `service_fn_ok ` is a helper to convert a function that
22
+ // `service_fn ` is a helper to convert a function that
21
23
// returns a Response into a `Service`.
22
24
async {
23
25
Ok :: < _ , hyper:: Error > ( service_fn ( hello) )
@@ -26,13 +28,7 @@ async fn serve() {
26
28
27
29
println ! ( "Listening on http://{}" , addr) ;
28
30
29
- if let Err ( e) = server. await {
30
- eprintln ! ( "server error: {}" , e) ;
31
- }
32
- }
33
-
34
- fn main ( ) {
35
- pretty_env_logger:: init ( ) ;
31
+ server. await ?;
36
32
37
- rt :: run ( serve ( ) ) ;
33
+ Ok ( ( ) )
38
34
}
0 commit comments