docs(server): tweaks to server doc example
This commit is contained in:
@@ -19,27 +19,30 @@
|
|||||||
//! ## Example
|
//! ## Example
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use hyper::{Body, Error, Response, Server};
|
//! use std::convert::Infallible;
|
||||||
|
//! use std::net::SocketAddr;
|
||||||
|
//! use hyper::{Body, Request, Response, Server};
|
||||||
//! use hyper::service::{make_service_fn, service_fn};
|
//! use hyper::service::{make_service_fn, service_fn};
|
||||||
//!
|
//!
|
||||||
|
//! async fn handle(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
|
||||||
|
//! Ok(Response::new(Body::from("Hello World")))
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
//! # #[cfg(feature = "runtime")]
|
//! # #[cfg(feature = "runtime")]
|
||||||
//! #[tokio::main]
|
//! #[tokio::main]
|
||||||
//! async fn main() {
|
//! 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 = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||||
//!
|
//!
|
||||||
//! // And a MakeService to handle each connection...
|
//! // And a MakeService to handle each connection...
|
||||||
//! let make_service = make_service_fn(|_| async {
|
//! let make_service = make_service_fn(|_conn| async {
|
||||||
//! Ok::<_, Error>(service_fn(|_req| async {
|
//! Ok::<_, Infallible>(service_fn(handle))
|
||||||
//! 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...
|
//! // And run forever...
|
||||||
//! if let Err(e) = server.await {
|
//! if let Err(e) = server.await {
|
||||||
//! eprintln!("server error: {}", e);
|
//! eprintln!("server error: {}", e);
|
||||||
//! }
|
//! }
|
||||||
|
|||||||
Reference in New Issue
Block a user