-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): update to
std::future::Future
BREAKING CHANGE: All usage of async traits (`Future`, `Stream`, `AsyncRead`, `AsyncWrite`, etc) are updated to newer versions.
- Loading branch information
1 parent
da9b031
commit 8f4b05a
Showing
37 changed files
with
1,524 additions
and
1,546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
#![feature(async_await)] | ||
#![deny(warnings)] | ||
extern crate hyper; | ||
extern crate pretty_env_logger; | ||
|
||
use hyper::{Body, Request, Response, Server}; | ||
use hyper::service::service_fn_ok; | ||
use hyper::rt::{self, Future}; | ||
use hyper::service::{make_service_fn, service_fn}; | ||
use hyper::rt; | ||
|
||
fn main() { | ||
pretty_env_logger::init(); | ||
async fn hello(_: Request<Body>) -> Result<Response<Body>, hyper::Error> { | ||
Ok(Response::new(Body::from("Hello World!"))) | ||
} | ||
|
||
async fn serve() { | ||
let addr = ([127, 0, 0, 1], 3000).into(); | ||
|
||
let server = Server::bind(&addr) | ||
.serve(|| { | ||
.serve(make_service_fn(|_| { | ||
// This is the `Service` that will handle the connection. | ||
// `service_fn_ok` is a helper to convert a function that | ||
// returns a Response into a `Service`. | ||
service_fn_ok(move |_: Request<Body>| { | ||
Response::new(Body::from("Hello World!")) | ||
}) | ||
}) | ||
.map_err(|e| eprintln!("server error: {}", e)); | ||
async { | ||
Ok::<_, hyper::Error>(service_fn(hello)) | ||
} | ||
})); | ||
|
||
println!("Listening on http://{}", addr); | ||
|
||
rt::run(server); | ||
if let Err(e) = server.await { | ||
eprintln!("server error: {}", e); | ||
} | ||
} | ||
|
||
fn main() { | ||
pretty_env_logger::init(); | ||
|
||
rt::run(serve()); | ||
} |
Oops, something went wrong.