docs(server): doc test to async/await
This commit is contained in:
committed by
Sean McArthur
parent
87b4850694
commit
13afb6e0da
@@ -19,32 +19,31 @@
|
|||||||
//! ## Example
|
//! ## Example
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! extern crate hyper;
|
//! # #![feature(async_await)]
|
||||||
//!
|
//! use hyper::{Body, Error, Response, Server};
|
||||||
//! use hyper::{Body, Response, Server};
|
//! use hyper::service::{make_service_fn, service_fn};
|
||||||
//! use hyper::service::service_fn_ok;
|
|
||||||
//!
|
//!
|
||||||
//! # #[cfg(feature = "runtime")]
|
//! # #[cfg(feature = "runtime")]
|
||||||
//! fn main() {
|
//! # #[hyper::rt::main]
|
||||||
//! # use hyper::rt::Future;
|
//! async fn main() {
|
||||||
//! // Construct our SocketAddr to listen on...
|
//! // Construct our SocketAddr to listen on...
|
||||||
//! let addr = ([127, 0, 0, 1], 3000).into();
|
//! let addr = ([127, 0, 0, 1], 3000).into();
|
||||||
//!
|
//!
|
||||||
//! // And a MakeService to handle each connection...
|
//! // And a MakeService to handle each connection...
|
||||||
//! let make_service = || {
|
//! let make_service = make_service_fn(|_| async {
|
||||||
//! service_fn_ok(|_req| {
|
//! Ok::<_, Error>(service_fn(|_req| async {
|
||||||
//! Response::new(Body::from("Hello World"))
|
//! Ok::<_, Error>(Response::new(Body::from("Hello World")))
|
||||||
//! })
|
//! }))
|
||||||
//! };
|
//! });
|
||||||
//!
|
//!
|
||||||
//! // Then bind and serve...
|
//! // Then bind and serve...
|
||||||
//! let server = Server::bind(&addr)
|
//! let server = Server::bind(&addr)
|
||||||
//! .serve(make_service);
|
//! .serve(make_service);
|
||||||
//!
|
//!
|
||||||
//! // Finally, spawn `server` onto an Executor...
|
//! // Finally, spawn `server` onto an Executor...
|
||||||
//! hyper::rt::run(server.map_err(|e| {
|
//! if let Err(e) = server.await {
|
||||||
//! eprintln!("server error: {}", e);
|
//! eprintln!("server error: {}", e);
|
||||||
//! }));
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! # #[cfg(not(feature = "runtime"))]
|
//! # #[cfg(not(feature = "runtime"))]
|
||||||
//! # fn main() {}
|
//! # fn main() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user