docs(server): doc test of Builder to async future
Signed-off-by: Weihang Lo <me@weihanglo.tw>
This commit is contained in:
committed by
Sean McArthur
parent
5da17df97f
commit
87b4850694
@@ -378,26 +378,28 @@ impl<I, E> Builder<I, E> {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # extern crate hyper;
|
/// # #![feature(async_await)]
|
||||||
|
/// # #[cfg(not(feature = "runtime"))]
|
||||||
/// # fn main() {}
|
/// # fn main() {}
|
||||||
/// # #[cfg(feature = "runtime")]
|
/// # #[cfg(feature = "runtime")]
|
||||||
/// # fn run() {
|
/// # #[hyper::rt::main]
|
||||||
/// use hyper::{Body, Response, Server};
|
/// # async fn main() {
|
||||||
/// use hyper::service::service_fn_ok;
|
/// use hyper::{Body, Error, Response, Server};
|
||||||
|
/// use hyper::service::{make_service_fn, service_fn};
|
||||||
///
|
///
|
||||||
/// // 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 NewService to handle each connection...
|
/// // And a MakeService to handle each connection...
|
||||||
/// let new_service = || {
|
/// let make_svc = 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(new_service);
|
/// .serve(make_svc);
|
||||||
///
|
///
|
||||||
/// // Finally, spawn `server` onto an Executor...
|
/// // Finally, spawn `server` onto an Executor...
|
||||||
/// # }
|
/// # }
|
||||||
|
|||||||
Reference in New Issue
Block a user